MongoDB Database Connection Strings
On this page
Note
URIs in Relational Migrator are optional. You can use the connection string forms to enter your connection details instead of manually providing URIs.
To start a migration job, Relational Migrator must connect to your MongoDB
database. Relational Migrator requires a username and password which has readWrite
access in the target database. This page describes
the procedure to make an authenticated user account and the Uniform Resource
Identifier (URI) formats for defining connections to your target
MongoDB database.
About this Task
Relational Migrator supports all connection string options except
appName
. Relational Migrator overrides theappName
connection string option when connecting to your MongoDB deployment. For details on MongoDB connection string options, see Connection Strings.Relational Migrator can use both Atlas and on-premises URIs. This page provides separate instructions for each deployment type.
Atlas
Connect to Your Deployment
To provision user accounts in Atlas you need to be logged in to the Atlas GUI.
Create a New User
In the Security section of the left navigation, click Database Access.
Click Add New Database User.
In the Authentication Method section of the Add New Database User modal window, select the box labeled Password.
Under Password Authentication, enter the username
migrator-service
for the new user in the top text field.Enter the password
password
for the new user in the lower text field.Under Database User Privileges, click Built-in Role.
Select Read and write to any database.
Click Add User.
Connection URI
Using the previously created account credentials, format the connection
URI for the target database. In this case MongoEnterprises
.
mongodb+srv://migrator-service:password@sandbox.xxxxx.mongodb.net/MongoEnterprises
On-Premises
In this example, use mongosh
to provision a user account that
connects to the MongoEnterprises
database.
This examples assume your deployment is running on localhost
and the
default port of 27017
.
Connect to Your Deployment
When connecting to your deployment, your user account requires the
createRole
permission in both the admin
and MongoEnterprises
databases.
Copy the following code with your admin credentials into a terminal to
connect to your deployment with mongosh
.
mongosh "mongodb://myadminuser:myadminpassword@localhost:27017/admin"
For details on mongosh
connections see :
Connecting to your MongoDB Deployment.
Create a New User
In mongosh
, run the following command to create a
user in the admin
database:
use admin db.createUser( { user: "migrator-service", pwd: "password", roles:[{role: "readWrite" , db:"MongoEnterprises"}] } )
Create the same user in the user in the MongoEnterprises
database:
use MongoEnterprises db.createUser( { user: "migrator-service", pwd: "password", roles:[{role: "readWrite" , db:"MongoEnterprises"}] } )
These commands:
Create a new user
migrator-service
with the passwordpassword
in theadmin
andMongoEnterprises
databases.Apply the
readWrite
system role to theMongoEnterprises
database for the usermigrator-service
.
Connection URI
Using the previously created account credentials, format the connection
URI for the target database. In this case MongoEnterprises
.
mongodb://migrator-service:password@localhost:27017/MongoEnterprises
Results
The MongoDB connection URI is optionally specified as part of the process for creating a Relational Migrator project or when creating a sync job.