Skip to content
Studio 3T - The professional GUI, IDE and client for MongoDB
  • Tools
    • Aggregation Editor
    • IntelliShell
    • Visual Query Builder
    • Export Wizard
    • Import Wizard
    • Query Code
    • SQL Query
    • Connect
    • Schema Explorer
    • Compare
    • SQL ⇔ MongoDB Migration
    • Data Masking
    • Task Scheduler
    • Reschema
    • More Tools and Features
  • Solutions
  • Resources
    • Knowledge Base
    • MongoDB Tutorials & Courses
    • Tool/Feature Documentation
    • Blog
    • Community
    • Testimonials
    • Whitepapers
    • Reports
  • Contact us
    • Contact
    • Sales Support
    • Feedback and Support
    • Careers
    • About Us
  • Store
    • Buy Now
    • Preferred Resellers
    • Team Pricing
  • Download
  • My 3T
search

Studio 3T Knowledge Base

  • Documentation
  • Tutorials
  • Workshops
Take the fastest route to learning MongoDB. Cover the basics in two hours with MongoDB 101, no registration required.
Start the free course

How to Compare MongoDB Collections

Posted on: 20/06/2018 (last updated: 30/09/2022) by Graham Thomson

In this post, we’ll show you how to:

  • Compare MongoDB collections located in different databases and/or servers
  • Analyze differences between their documents and fields
  • Sync your data as needed, and
  • Export the comparison results to a Word or CSV file

All using Studio 3T’s Data Compare and Sync feature.

Don’t have Studio 3T on your machine yet? Head to our Downloads page for the latest version.

Why you should diff your MongoDB

There are a number of situations where being able to conveniently analyze the differences between two database installations is extremely handy.

For example, you have a problem with your production system. All you know about it is that the problem lies somewhere in the database, but WHERE in the database? It worked fine yesterday, so if you compare the current database with yesterday’s backup, most likely you’ll find out what the problem is.

Additionally, it could be time to release an upgrade to the production system, but there are new configuration parameters required. The upgrade can be performed with a calm confidence when you can easily compare against the staging server and clearly see which parameters need to be introduced, changed or removed.

Or worse: an accidental update has removed vital configuration from the system, and it’s now crashing. You knew you should have taken a backup, but there just wasn’t time. And besides it was just a trivial change, so what could possibly go wrong?

But now, all you can do is sit and stare at your screen in horror and gulp down the bitter taste of regret. Unless of course, you can compare the differences and quickly identify which settings have been lost, and carry out an informed repair before anyone realizes your terrible blunder! (Of course, this NEVER HAPPENS on production systems, right? 🙂 )

More generally, being able to see how your data is changing is very powerful. Not only does it let you gain insight to your data, but it also provides confident control over the changes when you can see them explicitly and edit them directly.

Studio 3T’s Data Compare and Sync

First of all, download our MongoDB GUI in case you haven’t already. It’s available for Windows, Mac, and Linux.

Next, open Data Compare and Sync either by right-clicking on a collection or clicking on the Compare button.

This will open up a view where we can select source and target connections, which looks like this:

Comparing MongoDB collections starts by clicking the Compare button on the Studio 3T toolbar

Once you’ve chosen your source and target connections, it’s time to select the specific collections we want to compare.

Choose collections to compare

Simply drag the source database on top of the target database, and voilà! All collections with the same name in the source and target databases are automatically selected for comparison (highlighted in yellow in the screenshot below).

Simply drag the source database on top of the target database and their collections will automatically be selected for comparison

Of course, it’s not mandatory that collections need to have the same name. For example, if you need to compare the source collection current_customers with the target collection existing_customers, simply drag current_customers on top of existing_customers and it will be added to the comparison (highlighted in purple).

If you want to remove a particular pair of collections from the selection, simply right click it and choose Remove from comparison list. Alternatively, click the Remove button on the right of the comparison table.

Configure your data comparison

Studio 3T’s Data Compare and Sync feature also lets you configure data comparison settings, which can come in handy in case you only want to compare certain fields, filter based on certain criteria, etc.

To start, click on Configure to the right of the table. This will open up the Comparison Configuration window which has four tabs: Match On, Compare, Filter, and Projection. You can read about them in full here.

Configure your MongoDB data comparison: decide what fields to match on, what fields to compare, for example.

Run the analysis

OK, now that we’ve selected what we want to compare, hit the Run comparison button right above the table.

Click on Run comparison, well, to run your data comparison :)

When the run is completed, a tab will open for each pair of collections. Let’s take a closer look at accounts.

The Comparison Overview summarizes the differences found between your source and target collection

In the image above, we can see the comparison took 792 milliseconds and found seven differences in total: five differing documents, one document that only appeared on the source side, and one document that only appeared on the target side.

The Overview tab shows exactly what was compared. This is useful if we save the results to come back to them later, by which time the comparison configuration may have been updated. The overview page of the results provides a permanent record of what was actually compared.

Spot the difference(s)

OK, now it’s time for the main course! Click on the Differences tab.

The Differences tab shows you the differing documents and fields found in your source and target collections

Differing documents are highlighted in yellow, source-only documents in green and target-only in red, though in nice pastel shades that are easy on the eye.

You can even just show the differing documents only for a cleaner, more targeted overview by clicking on View Options:

With Studio 3T's Data Compare and Sync, you can choose to only show differing fields for a cleaner overview

Now let’s expand a document.

Expand and/or collapse fields and documents in one right-click

Here we can see the same highlighting pattern: yellow shows fields that are different, green shows source-only fields, and red shows target-only fields.

You can expand or collapse all documents in one right-click.

Export comparison results

For a more convenient data analysis and easier sharing across teams, simply click on the Export button under the Differences tab to export results as a CSV file.

Export comparison results from Studio 3T Data Compare and Sync

Sync MongoDB documents

We realize our source-only document should indeed be on the target collection, so we right click Copy Document to Target and confirm the copy operation.

Studio 3T lets you copy the source document to the target MongoDB database easily

Alright. Now we realize the target-only document is old and should no longer be present on the target.

No problem: We simply right-click and select Delete Document.

Easily remove documents from your MongoDB data comparison by clicking on Delete Document

Sync MongoDB fields

OK, we’ve done some syncing at document level, now we sync individual fields. View Options > Show Differing Fields Only will really come in handy here.

Looking at the first document, it looks like ‘pet:manatee’ on the target side is incorrect, but instead should be ‘pet:cat’ as it is on the source side.

Right click on either ‘pet:manatee’ or ‘pet:cat’. Since the field exists on both source and target, you can choose to either ‘Copy Field from Source’ or ‘Copy Field to Target’, respectively.

Copy field to target makes a sync job from source to target collections a breeze

You might also come across missing fields in the source document that should be copied over from the target document.

In this case, you would simply right click and select ‘Copy Field to Source’ if you clicked on the target side, or ‘Copy Field from Target’ if you clicked on the source side.

Studio 3T’s Data Compare and Sync lets you do a bi-directional sync on the same document, in that some changes are copied from the target document to the source, and other changes from the source to the target. Pretty neat, eh? 🙂

Sync MongoDB data via in-place editing

Alright, we’re done with the veg and potatoes, let’s center in on the steak!

For small changes, you don’t even need to invoke the right-click menu. Simply double-click a field and edit it directly – the diff status is updated in real time.

The best part: you can sync your data in-place by double clicking on a field

It’s been a pleasure

And that concludes our journey through how to compare MongoDB collections! I hope this tutorial on how to diff MongoDB has left you a little bit more powerful than when our journey first began.

Complement your new data comparison skills by checking out Schema Explorer, another nifty Studio 3T feature that will help tremendously in your data analysis. And if you haven’t downloaded our MongoDB GUI yet, here’s another chance 🙂


How helpful was this article?
This article was hideous
This article was bad
This article was ok
This article was good
This article was great
Thank you for your feedback!

About The Author

Graham Thomson

It all started with a Dragon 32… and has led to here, the most exciting place to be in software and databases right now. After helping hunt for the Higgs at CERN, and building large-scale, intelligent systems in industry, Graham is now doing the best job of all – building world-class tools that empower you to achieve world-class performance. Graham holds a Ph.D. in Computer Science from the University of Strathclyde.

Article navigation

Related articles

  • Compare Page
  • Data Compare and Sync
  • Working with MongoDB Collections: CRUD, Count, Sort, Limit Collection Size & More
  • How do you make Studio 3T export MongoDB collections to unique files? #Studio3T_AMA
  • How to get MongoDB statistics for all collections? #Studio3T_AMA

Studio 3T

MongoDB Enterprise Certified Technology PartnerSince 2014, 3T has been helping thousands of MongoDB developers and administrators with their everyday jobs by providing the finest MongoDB tools on the market. We guarantee the best compatibility with current and legacy releases of MongoDB, continue to deliver new features with every new software release, and provide high quality support.

Find us on FacebookFind us on TwitterFind us on YouTubeFind us on LinkedIn

Education

  • Free MongoDB Tutorials
  • Connect to MongoDB
  • Connect to MongoDB Atlas
  • Import Data to MongoDB
  • Export MongoDB Data
  • Build Aggregation Queries
  • Query MongoDB with SQL
  • Migrate from SQL to MongoDB

Resources

  • Feedback and Support
  • Sales Support
  • Knowledge Base
  • FAQ
  • Reports
  • White Papers
  • Testimonials
  • Discounts

Company

  • About Us
  • Blog
  • Careers
  • Legal
  • Press
  • Privacy Policy
  • EULA

© 2023 3T Software Labs Ltd. All rights reserved.

  • Privacy Policy
  • Cookie settings
  • Impressum

We value your privacy

With your consent, we and third-party providers use cookies and similar technologies on our website to analyse your use of our site for market research or advertising purposes ("analytics and marketing") and to provide you with additional functions (“functional”). This may result in the creation of pseudonymous usage profiles and the transfer of personal data to third countries, including the USA, which may have no adequate level of protection for the processing of personal data.

By clicking “Accept all”, you consent to the storage of cookies and the processing of personal data for these purposes, including any transfers to third countries. By clicking on “Decline all”, you do not give your consent and we will only store cookies that are necessary for our website. You can customize the cookies we store on your device or change your selection at any time - thus also revoking your consent with effect for the future - under “Manage Cookies”, or “Cookie Settings” at the bottom of the page. You can find further information in our Privacy Policy.
Accept all
Decline all
Manage cookies
✕

Privacy Preference Center

With your consent, we and third-party providers use cookies and similar technologies on our website to analyse your use of our site for market research or advertising purposes ("analytics and marketing") and to provide you with additional functions (“functional”). This may result in the creation of pseudonymous usage profiles and the transfer of personal data to third countries, including the USA, which may have no adequate level of protection for the processing of personal data. Please choose for which purposes you wish to give us your consent and store your preferences by clicking on “Accept selected”. You can find further information in our Privacy Policy.

Accept all cookies

Manage consent preferences

Essential cookies are strictly necessary to provide an online service such as our website or a service on our website which you have requested. The website or service will not work without them.

Performance cookies allow us to collect information such as number of visits and sources of traffic. This information is used in aggregate form to help us understand how our websites are being used, allowing us to improve both our website’s performance and your experience.

Google Analytics

Google Ads

Bing Ads

Facebook

LinkedIn

Quora

Hotjar

Functional cookies collect information about your preferences and choices and make using the website a lot easier and more relevant. Without these cookies, some of the site functionality may not work as intended.

HubSpot

Social media cookies are cookies used to share user behaviour information with a third-party social media platform. They may consequently effect how social media sites present you with information in the future.

Accept selected