How to connect remote mongodb server - OmIndia

Teach To India

Wednesday, November 22, 2017

How to connect remote mongodb server

Connect to remote MongoDB with your CLI


It appears that you are using the default MongoDB port (27017) so a lot of tutorials on connecting to MongoDB should be relevant.



my config file is
-----------------------------
systemLog:
    destination: file
    path: C:\MongoDbNew\log\mongo.log
storage:
    dbPath: C:\MongoDbNew\data\db
security:
    authorization: enabled
net:
    #bindIp: 10.130.13.215,127.0.0.1
    port: 27017
--------------------------------------------

I also notice you have a 10.x.x.x private IP address commented out in your bind configuration. Is the computer you want to connect from on the same network as the MongoDB instance you are trying to connect to?

If your MongoDB instance is remotely hosted, you will not be able to connect to a private IP address. In this case, you would either need to use a remote access solution like SSH or a VPN or have a public IP address for your MongoDB instance.


authorization: enabled

This means that you have authorization enabled. You will have to supply a username/password to connect to the MongoDB instance.

These pages should help you get started by giving examples on how to connect to MongoDB using the mongo shell or the C# driver:

To simplify testing the connection to your deployment, I suggest using the mongo shell before trying the C# driver or other applications:

1. Test you can successfully login directly from the Windows server hosting your MongoDB instance. For example:
mongo --host localhost --username YOUR_USERNAME --password YOUR_PASSWORD

2. Once logged in using the mongo shell, check that your bindIp values are set as expected. If you are connecting directly via an external IP address for your MongoDB server, this should be listed:
db.serverCmdLineOpts().parsed.net.bindIp

3. Finally, test you can connect remotely to the same MongoDB instance remotely:

mongo --host 10.130.13.215 --username YOUR_USERNAME --password YOUR_PASSWORD

--Is there any necessary for an inbound rule for this in window operating system.
--If you have the Windows firewall enabled for the environment hosting your MongoDB instance (which is definitely recommended), you will have to set the firewall to allow inbound connections to your MongoDB server on port 27017.

The actual method for firewall configuration will be specific to your environment, but the Security section of the MongoDB manual includes a basic example:

https://docs.mongodb.com/manual/tutorial/configure-windows-netsh-firewall/.
For a full list of security measures please review the MongoDB Security Checklist:

https://docs.mongodb.com/manual/administration/security-checklist/.

You could also post your Windows-specific questions to https://superuser.com/ should you need more guidance.



how can I connect to a remote mongo server from Mac OS terminal



4 comments:

Comments

Popular