Connecting to MongoDB Server

After successfully installing your MongoDB Server, you can establish a connection to verify its reachability.

If SSL Connection is Enabled

Run the following command at the command line to connect to MongoDB Server:

mongo --host <hostname> -u <username> -p <password> --authenticationDatabase <database_name> --ssl -- <ssl mode>

<ssl mode> — an option to set up the use of mixed SSL modes on a port.

Example: mongo --host 192.168.33.76:27017 -u admin -p abc123 --authenticationDatabase admin --ssl --sslAllowInvalidCertificates

If SSL Connection is Disabled

Run the following command at the command line to connect to the MongoDB Server:

mongo --host <hostname> -u <username> -p <password> --authenticationDatabase <database_name>

<hostname> — the IP address of the MongoDB Server and the port number that MongoDB service uses.

<username> — the admin username that you created to log into MongoDB Server.

<password> — the admin password used to log into MongoDB Server.

<database_name> — the name of the database to include authentication credentials of the created admin user.

Example: mongo --host 10.10.7.161:27017 -u mongodb -p mongodb --authenticationDatabase admin