MongoDB Atlas integration summary

Stitch’s MongoDB Atlas integration replicates data using the PyMongo 4.4.0 driver.

MongoDB Atlas feature snapshot

A high-level look at Stitch's MongoDB Atlas (v3) integration, including release status, useful links, and the features supported in Stitch.

STITCH
Release status

Released on July 27, 2023

Supported by

Stitch

Stitch plan

Standard

Supported versions

3.6 through 7.0

API availability

Available

Singer GitHub repository

singer-io/tap-mongodb

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, with prerequisites

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 3.6 and 7.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.

  1. Sign into your Stitch account, if you haven’t already.
  2. Click User menu (your icon) > Manage Account Settings and locate the Data pipeline region section to verify your account’s region.
  3. 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.

  1. 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.
  2. Click Network Access in the Security section on the left side of the page.
  3. Click + Add IP address on the Network Access page.

Add Whitelist Entry window for whitelisting IP addresses in MongoDB Atlas

  1. 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.
  2. Click Confirm.
  3. 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:

List of whitelisted Stitch's North America IP addresses in the Network Access page of MongoDB Atlas

Step 3: Create a Stitch database user

  1. 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.
  2. Click Database Access in the Security section on the left side of the page.
  3. Click the + Add new user button on the Database Access page.

  1. 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.
  2. Click the Add Default Privileges link.
  3. In the Default Privileges section:
    1. Select the read role from the dropdown and enter local into the Database field.
    2. Click the +add another role link.
    3. Select the readAnyDatabase role from the dropdown. The Database field should be automatically populated with admin.
  4. 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 local database.

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.

Step 4.1: Locate the database connection details in Mongo Atlas

  1. In MongoDB Atlas, click Clusters under the Atlas section on the left side of the page.
  2. Locate the cluster you want to connect to Stitch.
  3. Click Connect. This will display a window with several connection options. Connect with the Mongo Shell connection option in MongoDB Atlas
  4. Click Connect with the Mongo Shell.
  5. Click I have the Mongo Shell installed.
  6. For Select your Mongo Shell version, select 3.4 or earlier.
  7. 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>
    
  8. 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 is test-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 is 27017, 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 is test-shard-0.

Step 4.2: Define the database connection details

  1. If you aren’t signed into your Stitch account, sign in now.
  2. On the Stitch Dashboard page, click the Add Integration button.

  3. Locate and click the MongoDB icon.
  4. 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.

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:

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:

  1. Individual collections and fields

  2. All collections and fields

Click the tabs to view instructions for each selection method.

  1. In the Integration Details page, click the Collections to Replicate tab.
  2. Locate a collection you want to replicate.
  3. Click the checkbox next to the collection’s name. A blue checkmark means the collection is set to replicate.

  4. On the page that displays, click the Collection Settings button.
  5. In the Collection Settings page:
    1. Define the collection’s Replication Method, or skip this step if you want to use the integration’s default method.

    2. If using Key-based Incremental Replication, select a Replication Key.

    3. 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.
    4. When finished, click Update Settings.
  6. Repeat this process for every collection you want to replicate.

  7. Click the Finalize Your Selections button at the bottom of the page to save your data selections.
  1. Click into the integration from the Stitch Dashboard page.
  2. Click the Tables to Replicate tab.

  3. Navigate to the collection level, selecting any databases and/or schemas that contain collections you want to replicate.

  4. In the list of collections, click the box next to the Collection Names column.
  5. In the menu that displays, click Track AllCollections (Except Views):

    The Track AllCollections (Except Views) menu in the Collections to Replicate tab

  6. 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.

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.


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.