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 connector 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 connector 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.
MongoDB 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 connector connection properties:
- AuthScheme: SCRAM-SHA-1 for MongoDB versions 3.0, 3.2, 3.4, and 3.6.
- Server: The first server in the replica set. Or, you can specify a primary or secondary server here (the connector queries the servers in Server and ReplicaSet to find the primary).
cluster0-shard-00-00.mongodb.net
- Port: The port the server is running on (27017 is the default).
- ReplicaSet: 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: true to allow reading from secondary (slave) servers in the replica set.
- AuthDatabase: "admin" to connect to MongoDB Atlas. All MongoDB users for Atlas are associated with the admin database, their authentication database.
- Database: The database you want to read from and write to.
-
User: The username of a MongoDB user you added to your MongoDB project.
-
Password: The password of the MongoDB user.
- UseSSL: 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: The first server in the replica set. Or, you can specify another primary or secondary server here (the connector queries the servers in Server and ReplicaSet to find the primary). For example:
cluster0-shard-00-00.mongodb.net
- Port: The port the server is running on (27017 is the default).
- ReplicaSet: 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: true to allow reading from secondary (slave) servers in the replica set.
-
AuthScheme: PLAIN in LDAP authentication.
-
Database: The database you want to read from and write to.
-
AuthDatabase: "$external" to authenticate with an LDAP user.
-
User: 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: The password of the LDAP user.
-
UseSSL: 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 connector 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 connector connection properties:
- Server: 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 connector queries the servers in Server and ReplicaSet to find the primary).
abc123-d4-0.mongo.objectrocket.com
- Port: The port the server is running on (27017 is the default).
- ReplicaSet: 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: 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: The username of a MongoDB user you defined for the Database.
- Password: The password for the database user.
- UseSSL: true to enable TLS/SSL.