DBaaS Connections
When you connect to Atlas, ObjectRocket, or another database-as-a-service provider, there typically are a few variations on the procedure outlined in Establishing a Connection. The following sections show how to obtain the necessary connection properties for several popular services.
Atlas
You can authenticate to MongoDB Atlas with a MongoDB user or an LDAP user. The following sections show how to map Atlas connection strings to driver connection properties. To obtain the Atlas connection string, follow the steps below:
- In the Clusters view, click Connect for the cluster you want to connect to.
- Click Connect Your Application.
- Select either driver option to display a connection string.
Prerequisites
In addition to creating a MongoDB user and/or setting up LDAP, your Atlas project's white-list must include the IP address of the machine the driver is connecting from. To add an IP address to the white-list, select the Security tab in the Clusters view and then click IP Whitelist -> Add IP Address.
MonogDB User Credentials
Below is an example connection string providing a MongoDB user's credentials.
mongodb://USERNAME:[email protected]:27017,cluster0-shard-00-01.mongodb.net:27017,cluster0-shard-00-02.mongodb.net:27017/test?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin
Below are the corresponding driver connection properties:
-
Server: Set this to the first server in the replica set. Or, you can specify a primary or secondary server here (the driver will query the servers in Server and ReplicaSet to find the primary).
cluster0-shard-00-00.mongodb.net
- Port: Set this to the port the server is running on (27017 is the default).
- ReplicaSet: Set this to the other servers in the replica set. Server and ReplicaSet together specify all instances in the MongoDB replica set. Specify both the server name and port in ReplicaSet.
mycluster0-shard-00-01.mongodb.net:27017,mycluster0-shard-00-02.mongodb.net:27017
- SlaveOK: Set this to true to allow reading from secondary (slave) servers in the replica set.
- AuthDatabase: Set this to "admin" to connect to MongoDB Atlas. All MongoDB users for Atlas are associated with the admin database, their authentication database.
- Database: Set this to the database you want to read from and write to.
-
User: Set this to the username of a MongoDB user you added to your MongoDB project.
-
Password: Set this to the password of the MongoDB user.
- UseSSL: Set this to true. Atlas requires TLS/SSL.
LDAP
The following list shows the MongoDB Atlas requirements for authenticating with an LDAP user.
Below is an example command to connect with the mongo client:
mongo "mongodb://cluster0-shard-00-00.mongodb.net:27017,cluster0-shard-00-01.mongodb.net:27017,cluster0-shard-00-02.mongodb.net:27017/test?ssl=true&replicaSet=Cluster0-shard-0&authSource=$external" --authenticationMechanism PLAIN --username cn=rob,cn=Users,dc=atlas-ldaps-01,dc=myteam,dc=com
-
Server: Set this to the first server in the replica set. Or, you can specify another primary or secondary server here (the driver will query the servers in Server and ReplicaSet to find the primary). For example:
cluster0-shard-00-00.mongodb.net
- Port: Set this to the port the server is running on (27017 is the default).
- ReplicaSet: Set this to the other servers in the replica set. Server and ReplicaSet together specify all instances in the MongoDB replica set.
Below is an example value:
mycluster0-shard-00-01.mongodb.net:27017,mycluster0-shard-00-02.mongodb.net:27017
- SlaveOK: Set this to true to allow reading from secondary (slave) servers in the replica set.
-
AuthScheme: Set AuthScheme to PLAIN in LDAP authentication.
-
Database: Set this to the database you want to read from and write to.
-
AuthDatabase: Set this to "$external" to authenticate with an LDAP user.
-
User: Set this to the full Distinguished Name (DN) of a user in your LDAP server as the Atlas username. For example:
cn=rob,cn=Users,dc=atlas-ldaps-01,dc=myteam,dc=com
-
Password: Set this to the password of the LDAP user.
-
UseSSL: Set this to true. Atlas requires TLS/SSL.
ObjectRocket
To connect to ObjectRocket, you authenticate with the credentials for a database user. You can obtain the necessary connection properties from the control panel: On the Instances page, select your instance and then select the Connect menu to display a MongoDB connection string.
Prerequisites
In addition to adding a user for your database, you also need to allow access to the IP address for the machine the driver is connecting from. You can configure this by selecting your instance on the Instances page and then clicking Add ACL.
MongoDB User
Below is an example connection string providing the credentials for a MongoDB user:mongodb://YOUR_USERNAME:[email protected]:52826,abc123-d4-2.mongo.objectrocket.com:52826,abc123-d4-1.mongo.objectrocket.com:52826/YOUR_DATABASE_NAME?replicaSet=89c04c5db2cf403097d8f2e8ca871a1c
Below are the corresponding driver connection properties:
- Server: Set this to the first server in the replica set. Click Replica Set to obtain the server names. Or, you can specify another primary or secondary server here (the driver will query the servers in Server and ReplicaSet to find the primary).
abc123-d4-0.mongo.objectrocket.com
- Port: Set this to the port the server is running on (27017 is the default).
- ReplicaSet: Set this to the other servers in the replica set. Server and ReplicaSet together specify all instances in the MongoDB replica set.
Below is an example value:
abc123-d4-2.mongo.objectrocket.com:52826,abc123-d4-1.mongo.objectrocket.com:52826
- Database: Set this to the database you want to read from and write to. Note that this is also the authentication database for the user you are connecting with; database users cannot interact with other databases outside their database in ObjectRocket.
- User: Set this to the username of a MongoDB user you defined for the Database.
- Password: Set this to the password for the database user.
- UseSSL: Set this to true to enable TLS/SSL.