Change data capture, or CDC, streams changes as they happen. With MongoDB, a consumer can use Change Streams to subscribe to inserts, updates, replacements and deletes. RawTree’s MongoDB connector combines that stream with a starting snapshot so you can query the history of a collection without polling it repeatedly. The guide to processing repeated webhook deliveries shows a related distinction between observing several envelopes and counting a business action once. The CDC consumer should establish that distinction before an alert relies on its totals.
Plan how snapshots and live changes fit together
The RawTree MongoDB connector records the current MongoDB cluster time, scans the selected collection and emits existing documents as synthetic inserts. It then opens a Change Stream from the saved time. After processing changes, it saves resume tokens so a restart can continue from a checkpoint. If MongoDB can no longer resume from that point, the connector starts a new snapshot.
A row in the resulting table describes an observed mutation or a snapshot document. An insert count therefore includes existing documents captured during the first scan. A table that answers “what did this order look like on Tuesday?” needs different logic from one that answers “how many order updates did we receive Tuesday?” Keep the event history and define the current-state projection separately.
Connect one test collection
Use MongoDB Change Streams on a supported replica set or sharded cluster. Pick a database named shop_test and a collection named orders. Put the MongoDB URI and RawTree key in your runtime’s secret manager. Grant the connector access only to the collections it needs, and use a persistent checkpoint location. A test runner can use the repository’s supplied Compose or binary configuration.
Set mongodb.database to shop_test and include orders in mongodb.collections.include. Keep the default mongo_ table prefix for this example. Configure the destination with the RawTree service endpoint and use a credential scoped to the test database. The source collection maps to mongo_orders.
Seed an order before the connector starts so the snapshot has one document to send. Wait for the connector to report readiness. Then insert a new order, update the status, replace the document and delete it. Use distinct synthetic order IDs to trace each action.
Inspect the events by operation
SELECT _rt_op, count() AS records
FROM mongo_orders
WHERE _rt_ns = 'shop_test.orders'
GROUP BY _rt_op
ORDER BY records DESC;
Use _rt_id and _rt_ts to inspect a specific document’s event history. Open a representative record for each operation to see which data was captured. A MongoDB delete usually gives a consumer the key of the deleted document, and any pre-image depends on collection and stream configuration. Treat payload completeness as part of the consumer contract.
Test restart behavior with a known boundary
Stop the connector after a checkpoint and perform one more write. Restart it with the same persistent state, confirm that the new write arrives and compare the sequence with the source-side operations. The connector documents at-least-once delivery, so a downstream count that treats each replayed event as a separate business action can overstate totals. A document ID alone is too coarse for deduplication because many valid events can belong to the same document. Use a stable event identifier where you capture one, and test an expired checkpoint separately to understand what a resnapshot means for historical totals.
Keep a reconciliation log
Record the collection, table, test run identifier and approximate time of each operation. Compare those operations with what arrived in RawTree using the document key. Use the grouping query to check order-of-magnitude differences, then check individual recorded operations for duplicates. If the connector has performed a resnapshot, compare counts in a new time window to avoid confusing existing documents emitted during the scan with fresh application writes.
Decide what the table should drive before adding consumers. Replayed events can be acceptable when developers use the history to inspect changes. If a dashboard treats a row as a unique order transition, define the deduplication key at ingestion and retain it for the period in which you can replay data. Give downstream users the snapshot boundary so they can separate baseline counts from subsequent activity.
Prepare a small source workload
Begin with a collection that represents the changes your application actually makes. A useful order fixture includes a new document with two line items, a change to one field, a replacement that removes an optional field, and a deletion. Add two writes close together so you can verify that consumers can distinguish them. Use a separate fixture document for a field type change. Create the dataset with a disposable test database and choose IDs you can search for in both systems.
Write down the state of each document before starting the connector. For example, one order can already be marked paid and another can be awaiting fulfillment. After the initial snapshot, update the pending order, insert a third, and delete a fixture order. A consumer should be able to explain which rows came from existing documents and which changes happened during the exercise. Keep the times in UTC and write down whether each time came from MongoDB, the connector or the destination.
The source may continue to change while it is being scanned. A change observed during that interval can affect the version a scan reads and still be present in the later stream. Treat the boundary as an explicit reconciliation case. A staging run with a known concurrent update is more informative than a perfectly quiet snapshot. It shows why the sequence of captured records should drive a state projection according to a documented policy.
Separate event history from a table of current orders
For a support investigation, an event history can answer when someone changed an order, which operation occurred and how many times it was observed. A separate current-state projection should answer whether the order still exists and what its latest attributes are. To keep both views useful, agree on ordering, duplicate delivery and deletion handling before building queries on top of them.
For example, a delete event should remove the order from a current-state view even when the history still shows the earlier insert and update. If several operations share a timestamp, include an ordering or sequence value appropriate to the source and connector contract. Sorting by the destination arrival time alone can bring back a document that was already deleted when batches arrive late or replay.
Document how fields are supplied to the target for updates. Some consumers need only the changed fields. Others expect a complete current document before updating their view. Before choosing an approach, read one representative event per operation and check what the connector actually sends. A new change that modifies a single path is a useful example for catching a consumer that accidentally replaces an entire document with a partial payload.
Observe both lag and progress
Check the connector’s metrics for processed and sent records. If processed counts rise while delivery remains flat, investigate the target connection, credential scope or batching path. If both are flat, compare the last successful event time with a known new source write. Measure the interval between the source timestamp and the time the row is queryable. A peak in this measure can come from source load, buffering, destination limits or a recent restart.
Record whether the initial scan finished before evaluating streaming throughput. A large collection can change a rehearsal’s duration even if the live change rate is low. Start with one collection and measure the effect on the source. Expanding the scope to another collection should be a separate change. That makes it easier to tell whether a new table, different document shapes or the scan itself changed resource use.
Before enabling alerts or any downstream business logic, make a small recovery runbook. List the checkpoint location, the expected destination table, the most recent known test record and the person who can compare them. Include a decision for what to do if the source can no longer resume. Replaying a fixture exposes whether a new snapshot will confuse an existing dashboard, whether a projection needs to be rebuilt, and which queries can safely continue during recovery.
Choose a first production question
Start with one narrow query that benefits from the change log, such as the number of observed status updates by hour for a collection. Show the snapshot interval and any intentional gaps beside the chart. Add estimates or rates only after defining the event grain and confirming that duplicate records have the handling you expect. The first query should make the source, checkpoint, target and recovery responsibilities easy to see.