Collection Compare
The Collection Compare activity enables you to analyze differences between MongoDB collections across different databases, environments, or connections. With visual comparison setup using drag-and-drop linking, detailed results with categorized differences, and sync plan generation, you can ensure data consistency and reconcile discrepancies.
Quick Start
Get started with collection comparison in VisualLeaf:
- Open the Collection Compare activity from the toolbar
- Drag a collection from the Source panel on the left
- Drop it onto a collection in the Target panel on the right
- Configure match keys and filters in the link settings
- Click "Run Comparison" to execute
- Review results and optionally generate a sync plan
Comparison Setup
The comparison setup uses a three-panel layout with drag-and-drop functionality to create collection links.
Source and Target Panels
Both panels display your connected MongoDB instances in a hierarchical tree:
- Connection nodes: Show connection name with online/offline status (click broken link icon to connect)
- Database nodes: Expandable to show collections
- Collection nodes: Draggable items for creating comparison links
- Search filter: Filter nodes by name in each panel
The Source panel (teal) represents your reference data. The Target panel (orange) represents the destination you're comparing against.
Creating Comparison Links
To link collections for comparison:
- Expand the connection and database in the Source panel
- Drag a collection from the Source panel
- Drop it onto a collection in the Target panel
- A colored leader line appears connecting the two collections
- The link appears in the Comparison Links panel below
Comparison Links Panel
Each link in the panel displays:
- Color indicator: Click to change the link line color
- Source/Target info: Collection names, databases, and document statistics
- Time estimate: Estimated comparison duration based on collection size
- Match Keys: Fields used to identify matching documents (displayed as blue badges)
- Source/Target Filters: Optional query filters to limit compared documents
- Configure button: Open detailed link settings
- Remove button: Delete the comparison link
Link Configuration
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 |
Session Management
Comparison configurations can be saved and reused:
- Session Name: Enter a name for your comparison session in the header
- Save Session: Click to save the current link configuration (shown for new sessions)
- Tracked Session: Green badge indicates the session is saved and will auto-update on changes
Running Comparisons
Click the "Run Comparison" button to execute. The comparison runs as a background job with progress tracking:
- Progress indicator shows current operation and elapsed time
- Cancel button available to abort long-running comparisons
- Results are stored in the configured storage directory
Comparison Results
Results open in a new activity tab with multiple views:
Result Tabs
| 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 |
Results Table
The results table displays documents with the following columns:
- Checkbox: Select documents for sync operations
- Expand arrow: For modified documents, click the row or arrow to expand and see field-level differences
- Document ID: The match key value identifying the document
- Status: MODIFIED, MISSING_IN_RIGHT, MISSING_IN_LEFT, or IDENTICAL
- Source Value: Document preview from source (click to open in Collection View)
- Target Value: Document preview from target (click to open in Collection View)
Viewing Field Differences
For modified documents, click anywhere on the row to expand and see which fields differ. Each field row shows:
- Field Path: The path to the changed field (e.g., "address.city")
- Status badge: MODIFIED, ADDED, or REMOVED
- Source Value: The value from the source collection
- Target Value: The value from the target collection
Sync Operations
After reviewing comparison results, you can synchronize selected documents between collections.
Sync Direction
Use the direction toggle in the action bar to set sync direction:
- Source → Target: Push changes from source to target collection
- Target → Source: Pull changes from target to source collection
Click the toggle button to swap direction. The labels animate to show the current direction clearly.
Generating a Sync Plan
- Select documents using checkboxes (or use Select All/Deselect All buttons)
- Set the sync direction using the toggle
- Click "Generate Sync Plan"
- Review the sync plan preview showing all operations
Sync Plan Operations
| 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 |
Executing Sync
- Review the sync plan operations carefully
- Check the estimated sync time at the bottom of the modal
- Click "Execute Sync" to apply changes
- Monitor progress as operations complete
- Check the Log tab for operation history and any errors
- Use "Re-compare" button in the header to verify sync results
Sync Log
The Log tab records all sync operations with:
- Operation type: Insert, Update, Replace, Delete, or Recompare
- Status: Success or Failed
- Collection and database: Where the operation was performed
- Match key value: The document identifier
- Timestamp: When the operation occurred
- Error message: Details if the operation failed
Additional Features
Opening Documents
Click on source or target values in the results table to open documents:
- Click: Open document in Collection View
- Cmd/Ctrl + Click: Open in a new panel
- Bulk Open: Click the external link icon in column headers to open multiple documents
Storage Configuration
Comparison results are stored locally. Click the storage path displayed in the results header to open settings and configure the results directory.
Re-comparing
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.
Common Use Cases
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.
Pro Tips
- Use filters for large collections: Add source and target filters to limit comparison scope and improve performance.
- Choose appropriate match keys: Use unique identifiers like _id or business keys (email, orderId) for accurate document matching.
- Save sessions for recurring comparisons: Named sessions preserve your link configuration for quick future comparisons.
- Review before syncing: Always review the sync plan operations before executing to prevent unintended changes.
- Check the Log tab: After sync operations, review the log for any failed operations or errors.
- Re-compare after sync: Run a new comparison to verify that sync operations completed successfully.