Connecting to MongoDB

Modified: 22 Nov 2017 17:37 UTC

You can connect to MongoDB with your Joyent Public Cloud admin user credentials, which you can find in your portal. The MongoDB server is configured to listen to the localhost ( and with authentication enabled.

To run the commands in this page, you must be logged in as root or use sudo.

Logging in to MongoDB

Connect to a MongoDB database as the admin user and connect to the admin database.

# mongo -uadmin -p$(mdata-get mongodb_pw) admin
This command only works if you have not modified your original MongoDB credentials. If you have changed your credentials, use this command: # mongo -uadmin -ppassword admin

The first reference to admin specifies the user of the database that uses the default or set password to connect. The second reference to admin specifies the name of the database to which you want to connect.

If you connect without authenticating, MongoDB will log you in to the shell but will not let you execute any commands. Instead, you will see:

errmsg : need to login

If you provide the wrong password you will see:

login failed

Connecting a MongoDB to another machine

To connect other SmartMachines over a private network to your MongoDB appliance:

  1. SSH into your MongoDB appliance.
  2. Open /opt/local/etc/mongodb.conf for edit.
  3. Locate the bind_ip property.
  4. Set the value of the bind_ip property to the private IP of your MongoDB appliance. You can find the private IP of your appliance in your portal or by using ifconfig -a.
    For more information on private IPs, see [here](General FAQs.html#GeneralFAQs-privIps).
  5. Save the file and close it. You will need to restart the MongoDB server to set the changes.
  6. Run this command to restart the MongoDB server.
    svcadm restart mongodb