Collection Compare & Sync
The Collection Compare activity enables you to analyze differences between MongoDB collections across databases, environments, or connections — and between SQL tables and MongoDB collections via Debezium change data capture (CDC). With visual drag-and-drop link setup, categorized field-level diffs, and bidirectional sync plans, you can reconcile discrepancies and keep heterogeneous systems consistent.
VisuaLeaf supports two comparison modes selected automatically based on the source connection type:
Get started with collection comparison in VisualLeaf:
The comparison setup uses a three-panel layout with drag-and-drop functionality to create collection links.
Both panels display your connected MongoDB instances in a hierarchical tree:
The Source panel (teal) represents your reference data. The Target panel (orange) represents the destination you're comparing against.
To link collections for comparison:
Each link in the panel displays:
Click the configure (gear) button on a link to open the Link Configuration modal:
| Option | Description | Default |
|---|---|---|
Match Keys |
Fields used to identify matching documents between collections (e.g., _id, email, orderId) | _id |
Source Filter |
MongoDB query to filter source documents (e.g., {"status": "active"}) | None |
Target Filter |
MongoDB query to filter target documents | None |
Comparison configurations can be saved and reused:
Click the "Run Comparison" button to execute. The comparison runs as a background job with progress tracking:
Results open in a new activity tab with multiple views:
| Tab | Description |
|---|---|
Summary |
Overview with timing, status, document counts, differences breakdown, and comparison configuration |
All |
Combined view of all comparison results |
Modified |
Documents that exist in both collections but have different field values |
Missing in Source |
Documents present in target but not in source |
Missing in Target |
Documents present in source but not in target |
Log |
History of sync operations performed on this comparison |
The results table displays documents with the following columns:
For modified documents, click anywhere on the row to expand and see which fields differ. Each field row shows:
Each document is classified into one of four buckets so you can filter results and design targeted sync plans:
| Bucket | Meaning |
|---|---|
| Identical | Match keys align and every compared field is byte-equal on both sides |
| Modified | Match keys align but one or more fields differ — expandable diff shows path, source value, target value |
| Missing in Target | Document exists in the source (or SQL row exists) but not in the target Mongo collection |
| Missing in Source | Document exists in the target but not in the source |
Nested paths are compared with dot notation. Arrays are compared element-by-element with configurable order-sensitivity. BSON types (ObjectId, Date, Decimal128) are normalized before comparison so a Mongo Date equals a Postgres timestamptz at the same instant.
users Table to a Mongo users CollectionThis example uses Debezium CDC to compare a PostgreSQL public.users table against a Mongo app.users collection — a common check after migrating an auth service off Postgres.
wal_level = logical (edit postgresql.conf and restart)CREATE ROLE debezium REPLICATION LOGIN PASSWORD '...';pgoutput plugin (bundled with Postgres 10+) or wal2jsonOpen Connection Manager and add a PostgreSQL connection using a URI like:
jdbc:postgresql://db.internal:5432/appdb?user=debezium&password=...&sslmode=require
public schema, then drag the users tableapp.users in the Target Mongo panel — a leader line connects themSet the following in the Link Configuration modal:
id on the SQL side, _id on the Mongo side (VisuaLeaf coerces types for you)WHERE deleted_at IS NULL to exclude soft-deleted rows{"deletedAt": {"$exists": false}}created_at → createdAt, email_address → email, etc.Click Run Comparison. Behind the scenes VisuaLeaf spins up a Debezium 2.5.4 embedded engine, takes an initial snapshot of the filtered rows, and streams them into the diff engine while the Mongo cursor reads in parallel. Live progress shows rows read from Postgres, documents read from Mongo, and diffs computed so far.
Once complete, open the Modified tab to inspect fields that drifted — for example a user whose email changed in Postgres but was never re-synced to Mongo. Select rows, choose direction Source (Postgres) → Target (Mongo), and click Generate Sync Plan. The plan will show upserts scoped to just the drifted documents. Because Debezium keeps its offset, you can re-run the compare later and only the newly-drifted rows will show up.
After reviewing comparison results, you can synchronize selected documents between collections.
Use the direction toggle in the action bar to set sync direction. Plans are fully bidirectional — the same comparison result can produce either a forward sync or a reverse sync without re-running the compare.
Click the toggle button to swap direction. The labels animate to show the current direction clearly. Note: for SQL → MongoDB compares, only the Source → Target direction is enabled by default (writes back to Postgres/MySQL are gated behind an explicit setting to prevent accidental production writes).
Both compares and syncs stream progress in real time using Server-Sent Events (SSE):
| Operation Type | Description |
|---|---|
Insert |
Document will be inserted into the target collection (for missing documents) |
Update/Replace |
Existing document will be replaced with source values (for modified documents) |
Delete |
Document will be removed from the target collection |
The Log tab records all sync operations with:
Click on source or target values in the results table to open documents:
Comparison results are stored locally. Click the storage path displayed in the results header to open settings and configure the results directory.
Click "Re-compare" in the results header to run the comparison again with the same configuration. Useful after executing sync operations to verify changes were applied correctly.
Environment Synchronization
Compare development and production collections to identify drift. Use sync operations to push or pull changes between environments.
Data Migration Validation
After migrating data, compare source and destination to verify completeness. Check for missing or modified documents.
Backup Verification
Compare a collection against its backup to ensure data integrity and identify any discrepancies.
Multi-Region Consistency
Compare collections across different MongoDB instances or regions to ensure data consistency.
Download and start managing your MongoDB databases with ease.
Download Free Trial