This integration is powered by Singer's MongoDB Atlas tap and certified by Stitch. Check out and contribute to the repo on GitHub.
For support, contact Stitch support.
MongoDB Atlas integration summary
Stitch’s MongoDB Atlas integration replicates data using the PyMongo 3.8.0 driver.
MongoDB Atlas feature snapshot
A high-level look at Stitch's MongoDB Atlas (v1) integration, including release status, useful links, and the features supported in Stitch.
STITCH | |||
Release status |
Deprecated on February 14, 2020 |
Supported by | |
Stitch plan |
Standard |
Supported versions |
2.6 through 4.0 |
API availability |
Not available |
Singer GitHub repository | |
CONNECTION METHODS | |||
SSH connections |
Unsupported |
SSL connections |
Supported |
REPLICATION SETTINGS | |||
Anchor Scheduling |
Supported |
Advanced Scheduling |
Supported |
Table-level reset |
Supported |
Configurable Replication Methods |
Supported |
REPLICATION METHODS | |||
Log-based Replication |
Supported |
Key-based Replication |
Supported |
Full Table Replication |
Supported |
||
DATA SELECTION | |||
Table selection |
Supported |
Column selection |
Supported |
View replication |
Unsupported |
Select all |
Supported |
TRANSPARENCY | |||
Extraction Logs |
Supported |
Loading Reports |
Supported |
Connecting MongoDB Atlas
MongoDB Atlas setup requirements
To set up MongoDB Atlas in Stitch, you need:
-
Privileges in MongoDB Atlas that allow you to create/manage users. This is required to create the Stitch database user.
-
A MongoDB Atlas database using a version between 2.6 and 4.0. While older versions may be connected to Stitch, we may not be able to provide support for issues that arise due to unsupported versions.
We recommend always keeping your version current as a best-practice. If you encounter connection issues or other unexpected behavior, verify that your MongoDB Atlas version is one supported by Stitch.
Step 1: Verify your Stitch account's data pipeline region
First, you’ll log into Stitch and verify the data pipeline region your account is using. Later in this guide, you’ll need to grant Stitch access by whitelisting our IP addresses.
The IP addresses you’ll whitelist depend on the Data pipeline region your account is in.
- Sign into your Stitch account, if you haven’t already.
- Click User menu (your icon) > Edit User Settings and locate the Data pipeline region section to verify your account’s region.
-
Locate the list of IP addresses for your region:
Keep this list handy - you’ll need it later.
Step 2: Configure database connection settings
In this step, you’ll configure your MongoDB Atlas cluster to allow traffic from Stitch to access it. This is accomplished by whitelisting Stitch’s IP addresses in the cluster’s IP address whitelist in MongoDB Atlas.
- In MongoDB Atlas, navigate to the project containing the cluster you want to connect to Stitch. You can do this using the Context menu in the top left corner of the page.
- Click Network Access in the Security section on the left side of the page.
- Click + Add IP address on the Network Access page.
- Fill in the fields in the Add Whitelist Entry window as follows:
- Whitelist Entry: Paste one of the IP addresses you retrieved in Step 1 for your Stitch data pipeline region.
- Comment: Enter
Stitch
.
- Click Confirm.
- Repeat steps 3-5 until all the IP addresses for your Stitch data pipeline region have been added. This is what the list might look like for Stitch’s North America IP addresses:
Step 3: Create a Stitch database user
- In MongoDB Atlas, navigate to the project containing the cluster you want to connect to Stitch. You can do this using the Context menu in the top left corner of the page.
- Click Database Access in the Security section on the left side of the page.
- Click the + Add new user button on the Database Access page.
- Fill in the fields as follows in the Add New User window that displays:
- Username: Enter
stitch
. - Password: Enter a secure password for the Stitch user.
- Username: Enter
- Click the Add Default Privileges link.
- In the Default Privileges section:
- Select the
read
role from the dropdown and enterlocal
into the Database field. - Click the +add another role link.
- Select the
readAnyDatabase
role from the dropdown. The Database field should be automatically populated withadmin
.
- Select the
- Click Add User when finished.
See the Privileges list tab for an explanation of why these permissions are required by Stitch.
In the table below are the database user privileges Stitch requires to connect to and replicate data from a MongoDB Atlas database.
Privilege name | Reason for requirement |
read |
Required to read from the |
readAnyDatabase |
Required to read data from databases in the cluster. |
Step 4: Connect Stitch
In this step, you’ll complete the setup by entering the database’s connection details and defining replication settings in Stitch.
In this section:
Step 4.1: Locate the database connection details in Mongo Atlas
- In MongoDB Atlas, click Clusters under the Atlas section on the left side of the page.
- Locate the cluster you want to connect to Stitch.
- Click Connect. This will display a window with several connection options.
- Click Connect with the Mongo Shell.
- Click I have the Mongo Shell installed.
- For Select your Mongo Shell version, select 3.4 or earlier.
- Copy the connection string. It will look something like this:
mongo "mongodb://test-shard-00-00-ddreq.mongodb.net:27017,test-shard-00-01-ddreq.mongodb.net:27017/test?replicaSet=test-shard-0" --ssl --authenticationDatabase admin --username <username> --password <password>
-
Locate the following in the connection string:
- Host (Endpoint): This is the address of the instance you’re connecting to Stitch. It will be formatted like this:
<some-address>.mongodb.net
. In this example, the host istest-shard-00-00-ddreq.mongodb.net
. - Port: This is the port used to connect to the database. It follows the host string, separated by a colon (
:
). The default is27017
, which is what this example is also using. - Replica set: This is used to perform Log-based Incremental Replication. Locate
replicaSet
in the connection string - the value that follows is the name of the replica set. In this example, the replica set istest-shard-0
.
- Host (Endpoint): This is the address of the instance you’re connecting to Stitch. It will be formatted like this:
Step 4.2: Define the database connection details
- If you aren’t signed into your Stitch account, sign in now.
-
On the Stitch Dashboard page, click the Add Integration button.
- Locate and click the MongoDB icon.
-
Fill in the fields as follows:
-
Integration Name: Enter a name for the integration. This is the name that will display on the Stitch Dashboard for the integration; it’ll also be used to create the schema in your destination.
For example, the name “Stitch MongoDB Atlas” would create a schema called
stitch_mongodb_atlas
in the destination. Note: The schema name cannot be changed after the integration is saved. -
Host (Endpoint): Paste the Host (Endpoint) you retrieved in the previous step (4.1). This should be similar to
<some-address>.mongodb.net
. -
Port: Paste the Port you retrieved in the previous step (4.1). The default is
27017
. -
Username: Enter the Stitch MongoDB Atlas database user’s username.
-
Password: Enter the password for the Stitch MongoDB Atlas database user.
-
**: Enter the name of the MongoDB Atlas database where the Stitch user is to be authenticated. Stitch will ‘find’ all the databases you gave the Stitch user access to - this is needed only to complete the connection.
Note: If you’re connecting an Atlas-based MongoDB Atlas instance, this must be the
admin
database. See the Create a Mongo database user section for more info on this requirement. -
Authentication Database: This must be
admin
. This is the name of the Stitch user’s authentication database. This is the name of the database where the Stitch database user was initially created. -
Replica Set: Optional. The name of the replica set you retrieved in the previous step (4.1) to be used for Log-based Incremental Replication.
-
Include MongoDB database names in destination tables: Checking this setting will include schema names from the source database in the destination table name - for example:
<source_schema_name>__<collection_name>
.Stitch loads all selected replicated tables to a single schema, preserving only the collection name. If two collections canonicalize to the same name - even if they’re in different source databases or schemas - name collision errors can arise. Checking this setting can prevent these issues.
Note: This setting can not be changed after the integration is saved. Additionally, this setting may create table names that exceed your destination’s limits. For more info, refer to the Database Integration Table Name Collisions guide.
-
Step 4.3: Define the SSL connection details
Click the Connect using SSL checkbox. MongoDB Atlas requires SSL to connect successfully.
Step 4.4: Define Log-based Replication setting
In the Log-based Replication section, you can set this as the integration’s default Replication Method.
When enabled, tables that are set to replicate will use Log-based Incremental Replication by default. If you don’t want a table to use Log-based Incremental Replication, you can change it in the Table Settings page for that table.
If this setting isn’t enabled, you’ll have to select a Replication Method for each table you set to replicate.
Step 4.5: Create a replication schedule
In the Replication Frequency section, you’ll create the integration’s replication schedule. An integration’s replication schedule determines how often Stitch runs a replication job, and the time that job begins.
MongoDB Atlas integrations support the following replication scheduling methods:
-
Advanced Scheduling using Cron (Advanced or Premium plans only)
To keep your row usage low, consider setting the integration to replicate less frequently. See the Understanding and Reducing Your Row Usage guide for tips on reducing your usage.
Step 4.6: Save the integration
When finished, click Check and Save.
Stitch will perform a connection test to the MongoDB Atlas database; if successful, a Success! message will display at the top of the screen. Note: This test may take a few minutes to complete.
Step 5: Select data to replicate
The last step is to select the collections and fields you want to replicate.
Note: If a replication job is currently in progress, new selections won’t be used until the next job starts.
For MongoDB Atlas integrations, you can select:
-
Individual collections and fields
-
All collections and fields
Click the tabs to view instructions for each selection method.
- In the Integration Details page, click the Collections to Replicate tab.
- Locate a collection you want to replicate.
-
Click the checkbox next to the collection’s name. A blue checkmark means the collection is set to replicate.
- On the page that displays, click the Collection Settings button.
- In the Collection Settings page:
-
Define the collection’s Replication Method, or skip this step if you want to use the integration’s default method.
-
If using Key-based Incremental Replication, select a Replication Key.
- Optional: Select or exclude fields by entering a projection query in the Fields to Replicate section. Refer to the Selecting MongoDB Fields Using Projection Query guide for instructions and examples.
- When finished, click Update Settings.
-
-
Repeat this process for every collection you want to replicate.
- Click the Finalize Your Selections button at the bottom of the page to save your data selections.
- Click into the integration from the Stitch Dashboard page.
-
Click the Tables to Replicate tab.
-
Navigate to the collection level, selecting any databases and/or schemas that contain collections you want to replicate.
- In the list of collections, click the box next to the Collection Names column.
-
In the menu that displays, click Track AllCollections (Except Views):
- Click the Finalize Your Selections button at the bottom of the page to save your data selections.
Initial and historical replication jobs
After you finish setting up MongoDB Atlas, its Sync Status may show as Pending on either the Stitch Dashboard or in the Integration Details page.
For a new integration, a Pending status indicates that Stitch is in the process of scheduling the initial replication job for the integration. This may take some time to complete.
Initial replication jobs with Anchor Scheduling
If using Anchor Scheduling, an initial replication job may not kick off immediately. This depends on the selected Replication Frequency and Anchor Time. Refer to the Anchor Scheduling documentation for more information.
Free historical data loads
The first seven days of replication, beginning when data is first replicated, are free. Rows replicated from the new integration during this time won’t count towards your quota. Stitch offers this as a way of testing new integrations, measuring usage, and ensuring historical data volumes don’t quickly consume your quota.
MongoDB Atlas replication
MongoDB Replication Keys
Unlike Replication Keys for other database integrations, those for MongoDB have special considerations due to MongoDB functionality. For example: MongoDB allows multiple data types in a single field, which can cause records to be skipped during replication.
Refer to the MongoDB Replication Keys guide before you define the Replication Keys for your collections, as incorrectly defining Replication Keys can cause data discrepancies.
Heavily nested data and destination column limits
MongoDB documents can contain heavily nested data, meaning an attribute can contain many other attributes.
If your destination doesn’t natively support nested data structures, Stitch will de-nest them to load them into the destination. Depending on how deeply nested the data is and the per table column limit of the destination, Stitch may encounter issues when loading heavily nested data.
Refer to the Nested Data Structures guide for more info and examples.
Troubleshooting
Fields Missing from Replication Key Menu
If fields you expect to see are missing from a collection’s Replication Key menu, it may be that the fields aren’t indexed. Refer to the Mongo Replication Keys guide for more info.
Related | Troubleshooting |
Questions? Feedback?
Did this article help? If you have questions or feedback, feel free to submit a pull request with your suggestions, open an issue on GitHub, or reach out to us.