Real-Time CDC with MongoDB
A step-by-step guide to setting up Change Data Capture (CDC) from MongoDB with Estuary.

MongoDB is still one of the most popular document stores powering web applications today. Due to its flexible schema handling and tight integration with JSON-based libraries developers love working with it. It’s easy to set up, painless to maintain, and works at scale.
Because it’s the centerpiece of so many applications, it’s a common data engineering challenge to extract data out of MongoDB in order to power a data warehouse or enable other downstream use cases, like AI or operational analytics.
This tutorial will guide you through using Estuary to capture data from MongoDB using change data capture (CDC), requiring minimal configuration. By following these steps, you can empower your organization to leverage its application data in just a few minutes.
Video tutorial
What is CDC?
CDC, or Change Data Capture, is a method used to track and capture changes made to data in a database. It enables the real-time capture of insertions, updates, and deletions, providing a continuous stream of changes.
This stream of data is invaluable for keeping downstream systems synchronized and up-to-date with the source database, facilitating real-time analytics, replication, and data integration. In essence, CDC allows organizations to capture and react to data changes as they occur, ensuring data accuracy and timeliness across their systems.
Optionally, if you are interested in the intricacies of change data capture, head over to this article, where we explain the theory behind it - this is not a requirement for this tutorial, so if you want to dive in head first, keep on reading!
Understanding Change Events in MongoDB
Change events in MongoDB are notifications triggered by modifications to the database's data, configuration, or structure through a mechanism called change streams.
Change Streams in MongoDB are a convenient way for CDC, enabling real-time monitoring of data changes without having to directly interact with the underlying oplog. CDC processes leverage Change Streams to subscribe to data changes, capturing detailed events promptly as insertions, updates, or deletions occur.
This approach ensures efficient data propagation to downstream systems, scalability for high-throughput environments, and robust error handling for operations.
MongoDB supports various types of change events, each catering to different aspects of database operations. For data synchronization, the following three events are the only ones that matter:
- Insert Events: Triggered when new documents are inserted into a collection.

- Update Events: Fired upon modifications to existing documents, including field updates and replacements.

- Delete Events: Signaled when documents are removed from a collection.
In MongoDB, if you delete a key from a document, the corresponding change event that gets fired is an "update" event. This may seem counterintuitive at first, but in MongoDB, updates are atomic operations that can modify specific fields within a document, including removing keys. So, when a key is deleted from a document, MongoDB interprets it as an update operation where the specific field (i.e., the key) is being removed, resulting in an "update" event being generated in the oplog.

Introduction to Estuary
Estuary is the best tool for integrating CDC streams from MongoDB. Here are a few reasons why:
-
Unlike ELT vendors, Estuary does streaming CDC and incremental snapshots, not full snapshots or batch change data extraction. This puts less of a load on the source database and lowers latency.
-
Estuary also extracts exactly-and-only-once. As it streams snapshots and changes data it also stores it as a collection for later reuse, such as for backfilling or stream replay. ELT vendors require you to re-extract every time to want to resend the data or restart a change data stream.
-
Estuary supports both real-time and batch. Its streaming latency is within 100ms, and it always extracts in real-time. But it supports any latency from real-time to hours or days for destinations.
-
Estuary guarantees change data is delivered exactly once.
-
Estuary can also maintain type I and type II slowly changing dimensions directly into a target.
-
Estuary streaming has 50MB/sec per connection per table throughput rates, which is 5-10x any other benchmarks for CDC. It also scales horizontally to increase throughput.
Time to build a real-time CDC pipeline!
Prerequisites
To follow along with the tutorial, you’ll need the following:
-
An Estuary account. If you haven’t yet, sign up for free here. A fully-managed MongoDB Capture connector is ready for you to get started.
-
A MongoDB Atlas cluster: This tutorial uses Atlas as the source database, but Estuary supports other types of MongoDB deployments as well.
Setting up MongoDB
To prepare MongoDB for Estuary, you need to ensure the following prerequisites are met:
Credentials
Obtain the necessary credentials for connecting to your MongoDB instance and database. This includes credentials for authentication purposes, typically a username and password.
Read Access
Ensure that you have read access to the MongoDB database(s) from which you intend to capture data. MongoDB utilizes Role-Based Access Control (RBAC), so make sure your user account has the appropriate permissions to read data.

In MongoDB Atlas, any of the built-in Roles will work for the tutorial, but Estuary needs at least read permissions over the data you wish to capture if you wish to set up more granular, restricted permissions.
Configuration Considerations
-
If you haven't already, make sure you deploy a Replica Set-type MongoDB cluster. Change streams require a replica set in order to work. A replica set is a group of MongoDB deployments that maintain the same data set. If you are working following along with a fresh MongoDB Atlas project, you shouldn’t need to configure anything manually for this, as the default free-tier instance is a cluster of 3 replicas. To learn more about replica sets, see the Replication Introduction in the MongoDB manual.
-
Ensure that Estuary's IP addresses are allowlisted to allow access. We’ll show you how to do this in the next section.
Configure MongoDB
Let’s start by provisioning our database. As you can see, for this tutorial, you can just deploy an M0-category cluster, which is free to use.

After the cluster has finished provisioning, we’ll need to make sure that Estuary is able to connect to the database. For this, the only requirement with MongoDB Atlas is allowlisting the Estuary IP addresses.
Navigate to the “Network Access” page using the left hand sidebar, and using the “Add new IP address” button, create the list entry which enables the communication between the two services.

Next, find your connection string by navigating to the mongosh setup page by clicking the “Connect” button on the database overview section, then choosing the “Shell” option.
You’re not going to set up mongosh for this tutorial, but this is the easiest way to get ahold of the connection string we’ll be using.

Copy the connection string and head over to your Estuary dashboard to continue the tutorial.