How to allow only selected IPs to access mongodb v 8.0.4

Hello, I’m having a hard time to allow only selected IP to access my self-managed mongodb replica set. Am using mongodb v 8.0 and I’ve tried many ways and its not work.
For example

net:
  bindIP: 127.0.0.0, 54.5.xx.xx
  port:  27017

also

net:
  bindIP: 127.0.0.0;54.5.xx.xx
  port:  27017

This too

net:
  bindIP: "127.0.0.1, 54.5.xx.xx"
  port:  27017

and

net:
  bindIP: [127.0.0.0, 54.5.xx.xx]
  port:  27017

nothing is working

1 Like

See https://www.mongodb.com/docs/manual/reference/method/db.createRole/ specifically the role document key authenticationRestrictions which does what you want.

2 Likes

me too.
I just want to add one simple ip. why not working?

It is impossible for anyone to help you because you do not share anything about:

  1. what you are doing
  2. how you are doing it
  3. why does it fails, error message etc

Managed services like Atlas can help you do what you want when you do not have in-depth knowledge of network.

@steevej I think the original poster might have confused bindip with authenticationRestrictions and possibly @muyoungko might be confusing the two as well.

1 Like

Indeed.

That is why I mentioned managed services.

1 Like