Documentation

Collection Compare & Sync

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:

  1. Open the Collection Compare activity from the toolbar
  2. Drag a collection from the Source panel on the left
  3. Drop it onto a collection in the Target panel on the right
  4. Configure match keys and filters in the link settings
  5. Click "Run Comparison" to execute
  6. Review results and optionally generate a sync plan
Video COMP01 Collection Compare Walkthrough - Creating comparison links via drag-and-drop, configuring match keys and filters, running comparisons, reviewing results, and executing sync operations
Collection Compare setup interface showing Source panel (left), Target panel (right), connecting leader lines between linked collections, and the Comparison Links panel at the bottom

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.

To link collections for comparison:

  1. Expand the connection and database in the Source panel
  2. Drag a collection from the Source panel
  3. Drop it onto a collection in the Target panel
  4. A colored leader line appears connecting the two collections
  5. The link appears in the Comparison Links panel below

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
Comparison Links panel showing a configured link with match keys displayed as blue badges, source/target filters, document count statistics, and estimated comparison time

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:

Comparison Results view showing the Summary tab with timing information, status badge, document statistics (Source Docs, Target Docs, Identical, Modified), differences breakdown, and collection information

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
Expanded modified document row showing nested field-level differences with field paths, status badges (MODIFIED/ADDED/REMOVED), and source vs target values in separate columns

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

  1. Select documents using checkboxes (or use Select All/Deselect All buttons)
  2. Set the sync direction using the toggle
  3. Click "Generate Sync Plan"
  4. Review the sync plan preview showing all operations
Sync Plan Preview modal showing operation summary cards (Total Operations, Inserts, Updates, Deletes), scrollable operations table with type/collection/database/document ID columns, estimated time, and Execute Sync button

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

  1. Review the sync plan operations carefully
  2. Check the estimated sync time at the bottom of the modal
  3. Click "Execute Sync" to apply changes
  4. Monitor progress as operations complete
  5. Check the Log tab for operation history and any errors
  6. 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

  1. Use filters for large collections: Add source and target filters to limit comparison scope and improve performance.
  2. Choose appropriate match keys: Use unique identifiers like _id or business keys (email, orderId) for accurate document matching.
  3. Save sessions for recurring comparisons: Named sessions preserve your link configuration for quick future comparisons.
  4. Review before syncing: Always review the sync plan operations before executing to prevent unintended changes.
  5. Check the Log tab: After sync operations, review the log for any failed operations or errors.
  6. Re-compare after sync: Run a new comparison to verify that sync operations completed successfully.

Ready to try VisuaLeaf?

Download and start managing your MongoDB databases with ease.

Download Free Trial