I am trying to connect to a replica set using “MongoClientSettings” and “ConnectionString” but as the replica set is being started using “bind_ip_all”.
So, how I can connect to the replica set.
In normal cases it will come like mongodb://XXX.XX.XX.XX:27017/admin
But in case of “bind_ip_all” what I will keep in the ip part.
In the url is like this mongodb://--replSet:27017/admin
Note: This we are trying to do on the fly in any system where Mongo is installed and we try to discover that from the process and try to connect to the DB to get the DB metrics. So, I might not be having idea what hard coded IP I can kept over there.
The bindIp configuration option in MongoDB determines which network interfaces the server will listen on for incoming connections. By setting bindIp to 0.0.0.0, MongoDB listens for connections on all available network interfaces. In simple terms, any computer that can reach your MongoDB server can attempt to connect to it.
However, it’s important to note that the bindIp setting does not specify the IP address or port for the replica set. To connect your application with the replica set, you can directly specify the port of the primary member. You can identify the primary member using the rs.status() command from any member of the replica set.
Follow the documentation on Connection Strings for more information.
Regarding the MongoDB image you mentioned (image: mongo:4.4.29), it appears to have reached the end of its life. For more details, you can refer to the MongoDB Legacy Support documentation. We recommend using the latest MongoDB version to take advantage of new features and bug fixes.
If you’d like to simplify database management, consider using an Atlas cluster—a fully managed cloud database service by MongoDB. Atlas allows you to easily deploy, manage, and scale MongoDB databases in the cloud. You can create your first free tier Atlas cluster and get started.
Feel free to reach out with any further questions.