MongoDB Replica Set Setup Guidelink
Follow these instructions to connect your MongoDB replica set to your destination using Fivetran.
Prerequisiteslink
To connect your MongoDB replica set to Fivetran, you need:
- MongoDB version 2.6 to 4.2
- Your replica set's IP (e.g.,
1.2.3.4
) or domain (your.server.com
) - Your replica set's port (usually
27017
)
NOTE: Fivetran does not support Mongo tiers M0, M2, or M5 because MongoDB's smaller managed tiers do not provide oplogs. We need oplogs to perform incremental updates.
Setup instructionslink
Choose connection methodlink
First, decide whether to connect Fivetran to your MongoDB replica set directly or using an SSH tunnel.
IMPORTANT: Your MongoDB server must have replication enabled already. If replication is not enabled, follow MongoDB's replica set deployment instructions before proceeding.
Connect directly (TLS required)
IMPORTANT: You must have TLS enabled on your replica set to connect directly to Fivetran. Follow MongoDB's TLS configuration instructions to enable TLS on your replica set.
Fivetran connects directly to your MongoDB replica set. This is the simplest and most secure method.
To connect directly, configure your firewall and/or other access control systems to allow incoming connections to your MongoDB port (usually27017
) from Fivetran's IPs for your replica set's region. For help, see MongoDB's Security documentation.
Connect using SSH (TLS optional)
Fivetran connects to a separate server in your network that provides an SSH tunnel to your replica set. 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 SSH connection instructions. If you want Fivetran to tunnel SSH over TLS, follow MongoDB's TLS configuration instructions to enable TLS on your replica set.
Create userlink
Create a database user for Fivetran using either the MongoDB shell or MongoDB Atlas.
MongoDB shell
-
Open the MongoDB shell.
-
Connect to your replica set or primary node using the MongoDB shell as an admin user.
-
Go to the
admin
database. -
Execute the following command to create a user for Fivetran. Choose a memorable name (for example,
fivetran
). Replace<password>
with a password of your choice.use admin db.createUser({ user: "fivetran", pwd: "<password>", roles: [ "readAnyDatabase" ] })
TIP : The Mongo shell command to create a user is
db.AddUser()
for versions 2.x.For v3.4 and greater, the built-in role
readAnyDatabase
no longer includes thelocal
database. Instead, you must create the user with the following roles. Replace<password>
with a password of your choice.use admin db.createUser({ user: "fivetran", pwd: "<password>", roles: [ "readAnyDatabase", {role: "read", db: "local"} ] })
Read MongoDB's built-in roles documentation for more details.
MongoDB Atlas
-
Log in to the MongoDB Atlas dashboard.
-
In the Security section of the left menu, select Database Access.
-
Click New Database User.
-
Choose the password authentication method.
-
Enter a username (for example,
fivetran
) 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:
readAnyDatabase
read on the local database
-
Click Add User.
For more information, see MongoDB Atlas' configure users documentation.
Set oplog sizelink
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 the MongoDB shell or MongoDB Atlas:
- MongoDB shell: Follow MongoDB's changing the oplog size tutorial.
- MongoDB Atlas: Follow MongoDB Atlas' set oplog size tutorial.
If you are using MongoDB version 4.0 or later, you must also enable change streams on all collections. Learn how in MongoDB's access control documentation.
Finish Fivetran configurationlink
-
In your connector setup form, 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, do one of the following:
- Enter the hostname and port number for your primary node and all replicas. Each entry should be a hostname or IP address that is appended by a colon and the port number (for example,
server.example.com:27017
or1.2.3.4:27017
). Use the plus icon to add new fields until you have added all nodes. - Enter the SRV host record for your MongoDB instance. This will be a
mongodb+srv://
URL value, such asmongodb+srv://server.example.com/
.
NOTE: Do not include any path contents after the top-level domain in this URL.
- Enter the hostname and port number for your primary node and all replicas. Each entry should be a hostname or IP address that is appended by a colon and the port number (for example,
-
Enter the Fivetran-specific user that you created in Step 2 (for example,
fivetran
). -
Enter the password for the Fivetran-specific user that you created in Step 2.
-
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 Step 1, set the Require TLS through tunnel toggle to ON.
-
Click Save & Test. Fivetran will take it from here and sync your data from your MongoDB replica set.
Related articleslink
description Connector Overview
account_tree Schema Information
settings API Connector Configuration