MongoDB Replica Set Setup Guide
Follow these instructions to connect your MongoDB replica set to your destination using Fivetran.
Setup instructions
Find host identifiers
You need the MongoDB replica set's host identifier and, optionally, the alternative host identifiers to configure Fivetran. The replica set's host identifier has one of the following formats:
| Format | Example |
|---|---|
| SRV host identifier | mongodb+srv://example.mongodb.net |
| Connection string | mongodb://mongodb0.example.com:27017,mongodb1.example.com:27017,mongodb2.example.com:27017 |
| Domain and port | your.server.com:27017 |
| IP address and port | 1.2.3.4:27017 |
NOTE:
For SRV host identifier and Connection string, we support
Optionally, you can use to isolate queries from your operational workload and improve cluster reliability and performance, by specifying a connection string similar to the following example:
mongodb+srv://example.mongodb.net/?readPreference=secondary&readPreferenceTags=nodeType:ANALYTICSOptionally, you can specify the in the connection string based on your priority as shown below:
Read Preference Priority secondaryPreferred(default)Optimal performance primaryPreferredorsecondaryPreferredHigh availability nearestOptimal performance for geographically distributed data Using the
primary/primaryPreferredread preference might affect operational performance of your cluster
Find your host identifiers using either MongoDB Atlas or the MongoDB shell.
MongoDB Atlas
Log in to the .
In the Cluster Overview tab, click Connect.

Select Connect your application.

Copy the SRV host identifier.

MongoDB shell
IMPORTANT: Your MongoDB server must have replication enabled already. If replication is not enabled, follow MongoDB's before proceeding.
- Connect to your replica set or primary node using the MongoDB shell as an Admin user.
- Execute the
db.adminCommand( { replSetGetStatus : 1 } ).memberscommand. - Copy the host identifier and optionally the alternative host identifiers.
Allow database access
Create a database user for Fivetran using either MongoDB Atlas or the MongoDB shell.
MongoDB Atlas
- Log in to the .
- In the left-hand navigation menu, go to Security > Database Access.
- Click New Database User.
- Choose the password authentication method.
- Enter the username and password for the new Fivetran user.
- In the Database User Privileges drop-down menu, select Grant Specific User Privileges.
- Under Specific Privileges, add the following roles/privileges:
readAnyDatabasereadon thelocaldatabase (Only for MongoDB version below 4.0)
- Click Add User.
TIP: To learn how to restrict the Fivetran user's access to a subset of the databases, see the .
For more information, see MongoDB Atlas' .
MongoDB shell
Open the MongoDB shell.
Connect to your replica set or primary node using the MongoDB shell.
Execute the following command to create a user for Fivetran. Replace
<username>and<password>with a username and password of your choice.use admin db.createUser({ user: "<username>", pwd: "<password>", roles: [ "readAnyDatabase", {role: "read", db: "local"} ] })content_copyTIP : The Mongo shell command to create a user is
db.AddUser()for versions 2.x.
For more information, see MongoDB's .
Choose connection method
Decide whether to connect Fivetran to your MongoDB cluster directly, using an SSH tunnel, or using a private link. For more information about the connection options, see .
TIP: To enable TLS on your replica set, follow MongoDB's .
Connect directly (TLS required)
Fivetran connects directly to your MongoDB cluster. This is the simplest method. To connect directly, configure your firewall and/or other access control systems to allow incoming connections to your MongoDB cluster from for your cluster region. For more information, see MongoDB's .
Use either MongoDB Atlas or the MongoDB shell.
MongoDB Atlas
- Log in to the .
- In the Cluster Overview tab, make a note of MongoDB cluster cloud service provider and region.
- In the left-hand navigation menu, go to Security > Network Access.
- Click Add IP address.
- Allow for your MongoDB cluster's cloud service provider and region.
- In the Access List Entry field, enter the Fivetran IP and click Confirm.
MongoDB shell
For steps to safelist , see MongoDB's .
Connect using SSH (TLS optional)
Fivetran connects to a separate server in your network that provides an SSH tunnel to your cluster. You must connect through SSH if your database is in an inaccessible subnet.
To connect using SSH, configure your firewall and/or other access control systems to allow incoming connections to your MongoDB port (usually 27017) from your SSH tunnel server's IP.
Before you proceed to the next step, you must follow our . If you want Fivetran to tunnel SSH over TLS, follow MongoDB's to enable TLS on your cluster.
(Optional) Connect using AWS PrivateLink, Azure Private Link, or Google Cloud Private Service Connect Beta
IMPORTANT: You must have a Business Critical plan to use AWS PrivateLink, Azure Private Link, or Google Cloud Private Service Connect.
MongoDB Atlas
You can connect Fivetran to your MongoDB Atlas database using either AWS PrivateLink or Azure Private Link. Fivetran uses your chosen service to move your data securely between our system and your MongoDB Atlas database.
Configure a using either the Atlas CLI or Atlas UI depending on your service and cloud provider in the destination.
Atlas CLI
- Make sure that the status of the private endpoint service is Available.
NOTE: It can take several minutes for the service to be available. If the status is not Available, wait for some time till the endpoint service is Available.
- Run the
atlas privateEndpoints <aws|azure|gcp> describecommand. - Send the response to your Fivetran account manager.
Atlas UI
- During configuration using the Atlas UI, a Creating Atlas Endpoint Service message is displayed on the setup dialogue box. Close the dialog box.
- Go to the Network Access > Private Endpoint page.
- Copy the value of the Atlas Endpoint Service and send it to your Fivetran account manager.
- Make sure that the status of the private endpoint service is Available.
We create an interface endpoint inside the Fivetran network. We send you the ID and IP address of the endpoint.
NOTE: We don't send the IP address for AWS PrivateLink interface endpoints.
Finalize the private endpoint configuration on MongoDB Atlas using the Atlas CLI or Atlas UI:
Atlas CLI
AWS PrivateLink
- Use the
atlas privateEndpoints aws interfaces create <endpointServiceId> --privateEndpointId <endpointInterfaceId>command. - Replace the values marked with
<>.endpointServiceIdis the ID of the private endpoint service created above andendpointInterfaceIdis the interface endpoint ID provided by Fivetran.
NOTE: For more information, see .
Azure Private Link
- Use the
atlas privateEndpoints azure interfaces create <endpointServiceId> --privateEndpointId <endpointInterfaceId> --privateEndpointIpAddress <endpointInterfaceIPAddress>command. - Replace the values marked with
<>.endpointServiceIdis the ID of the private endpoint service created above,endpointInterfaceIdis the interface endpoint ID provided by Fivetran, andendpointInterfaceIPAddressis the interface endpoint IP address provided by Fivetran.
NOTE: For more information, see .
Atlas UI
- Go to the Network Access > Private Endpoint page.
- In the Actions column, click the Edit button.
- Fill out the fields in a dialog with values provided by Fivetran and click Create.
- On the Network Access / Private Endpoint page, make sure that the Endpoint status and Atlas Endpoint Service Status is Available.
- Use the
NOTE: Use either a DNS seed list connection or standard connection string to configure the MongoDB Fivetran connector.
AWS-, Azure-, or GCP-hosted MongoDB
You can also connect Fivetran to a MongoDB database hosted on AWS, Azure or GCP VMs using Private Link. Learn how in our , , or .
(Optional) Set oplog size
Set the oplog size so that it can retain at least 24 hours' worth of changes. We recommend increasing the size to retain seven days' worth of data.
Adjust your oplog size using either MongoDB Atlas or the MongoDB shell:
- MongoDB Atlas: Follow MongoDB Atlas' .
- MongoDB shell: Follow MongoDB's .
Choose pack mode
Choose between packed mode or unpacked mode. By default unpacked mode is selected, where Fivetran unpacks one layer of nested fields and infer types. In packed mode, we write the data without unpacking.
For more information, see our .
Finish Fivetran configuration
In your , enter a Destination schema prefix. This prefix applies to each replicated schema and cannot be changed once your connector is created.
In the Host and ports field, enter the host identifiers you found in .
Enter the Fivetran-specific User that you created in .
Enter the Password for the Fivetran-specific user that you created in .
Choose your Connection Method. If you selected Connect via an SSH tunnel, provide the following information:
- SSH hostname (do not use a load balancer's IP address/hostname)
- SSH port
- SSH user
- If you enabled SSL/TLS on your database in , set the Require TLS through tunnel toggle to ON.
Click Save & Test. Fivetran tests and validates our connection to your MongoDB replica set. Upon successful completion of the setup tests, you can sync your data using Fivetran.
Setup tests
Fivetran performs the following tests to ensure that we can connect to your MongoDB cluster and that it is properly configured:
- The Connecting to SSH Tunnel Test validates the SSH tunnel details you provided in the setup form. It then checks that we can connect to your database using the SSH Tunnel. (We skip this test if you aren't connecting using SSH.)
- The Validate Host Test validates the database credentials you provided in the setup form. It then verifies that the database host is not private and checks that we can connect to the host.
- The Validating Certificate Test generates a pop-up window where you must choose which certificate you want Fivetran to use. Select the root certificate to trust all the configured hosts. It then validates that certificate and checks that we can connect to your database using TLS. (We skip this test if you aren't connecting directly.)
- The Connecting to Host Test connects to your database instance and checks if we can access the schemas in your database.
- The Database Access Test verifies if we have the permissions to query at least one collection.
- The Change Streams/Oplog Access Test checks if we can access the change streams. If we can't access the change streams, it then verifies if we can access the oplog and if the oplog contains at least 24 hours' worth of changes.
NOTE: The tests may take a few minutes to finish running.
Related articles
Comments
0 comments
Please sign in to leave a comment.