Connecting to your MongoDB Database

You can retrieve the connection string to your database from the Task manager on the dashboard. Click on DB Actions → Database Connect.

You can also force clients connecting to your database to use SSL by selecting the Enable SSL checbox and clicking on save changes.

Enable database SSL connections

The connecting string displayed on the dashboard is of the format.

mongodb://username:password@host:port/databasename

Arguments

username
This is the default username created for your Database server. You cannot change this value at any point in time
password
An auto generated password to secure your database. You can change this value at anytime from the dashboard by navigating to DB Actions → Change password.
host
The hostname assigned to your database server.
port
The TCP listening port of the database server.
databasename
The name of the default database created when your server was first deployed.

Connecting to your database from Apps hosted on NodeChef.

The NodeChef App container runtime automatically creates the below environment variables which can be used to connect to your MongoDB database. Note, when SSL is enabled or your password is changed, the container runtime automatically changes the values of these environment variables to coresspond with your changes.


Connecting to the Mongo Shell

The Mongo shell is a powerful command line utility which can be used to perform CRUD operations againt your database. We highly recommend this tool although you can also use GUI based IDE tools as well.

For a complete overview on the usage of the Mongo shell, reference the MongoDB docs. The basic command required to connect to connect to your database from Mongo shell is of the below format

mongo host:port/databasename -u username -p password For SSL enabled connections. mongo host:port/databasename -u username -p password --ssl --sslCAFile /home/my_nodechef_ca_file For SSL enabled connections without the sslCAFile. mongo host:port/databasename -u username -p password --ssl --sslAllowInvalidCertificates

Connecting to the Local database which contains the oplog

To connect to your local database, simply change the databasename parameter in the connection string to "local" and add the query string "?authSource=databasename"

For example, for the given connection string. mongodb://cat:meow@cat-1.noodechef.com/cat You can use the below connection string to connect to the local database. mongodb://cat:meow@cat-1.nodechef.com/local?authSource=cat