How to Copy and Sync a Local MongoDB Collection to Atlas

serena_wright1 pts0 comments

= 1024) leftSidebarOpen = false; if(window.innerWidth >= 1280) rightSidebarOpen = false"<br>:class="{ 'dark': $store.theme.dark, 'left-sidebar-closed': !leftSidebarDesktop, 'right-sidebar-closed': !rightSidebarDesktop, 'overflow-hidden': leftSidebarOpen || rightSidebarOpen, 'sidebars-closed': !leftSidebarDesktop && !rightSidebarDesktop }">

How to Copy and Sync a Local MongoDB Collection to Atlas

Skip to content

Navigation

if (window.innerWidth

Preferences

Layout

Save Sidebar view

Remember if sidebars are open or closed across pages.

Save Sidebar layout preference

Enable Bookmarks

Save your favourite articles locally in this browser.

Enable Local Bookmarks

let scroll = window.scrollY;<br>let docHeight = document.documentElement.scrollHeight - window.innerHeight;<br>this.progress = docHeight > 0 ? Math.max(0, Math.min(1, scroll / docHeight)) : 0;<br>this.ticking = false;<br>});<br>}"<br>@scroll.window.passive="update()"<br>@resize.window.passive="update()"<br>x-init="update()"<br>class="fixed top-0 left-0 w-full h-[3px] z-[100] pointer-events-none">

VisuaLeaf Mongo Sync copies a local MongoDB collection to Atlas and keeps changes in sync.

Moving data from a local MongoDB database to Atlas usually means exporting files, importing them again, and repeating the same process when something changes.<br>I wanted to test a simpler way in VisuaLeaf: copy a local collection to MongoDB Atlas and keep the Atlas collection updated automatically.<br>For this example, I used a local visits collection containing seven documents. The documents included ordinary fields, nested objects, arrays, dates, and ObjectIds, so I could also check whether the original MongoDB structure remained intact in Atlas.<br>Here is the complete process, followed by an insert, update, and delete test.<br>What I used<br>My source and target were:

Role<br>Connection<br>Database<br>Collection

Source<br>Local Replica Set<br>database_compare_demo<br>visits

Target<br>MongoDB Atlas<br>database_compare_demo<br>visits_atlas_sync

I used a different target collection name so I could verify the copied data without mixing it with anything already stored in Atlas.<br>The local source was a replica set because continuous synchronization relies on MongoDB change streams. Change streams are available for replica sets and sharded clusters, not standalone MongoDB deployments. (MongoDB change streams)<br>If the source is standalone, the job can still perform an initial copy, but it cannot continue watching for later changes.<br>The local visits collection before it was copied to Atlas.Preparing the Atlas connection<br>Before creating the sync job, I made sure VisuaLeaf could write to my Atlas cluster.<br>Before using a standard Atlas connection, I configured two access items:<br>A database user with permission to access the target database.<br>My computer’s public IP address added to the project’s IP access list.<br>Atlas database users are separate from the account used to sign in to the Atlas website. For this test, I used a database user with read and write access to database_compare_demo.<br>I added only my current IP address to the Atlas access list instead of allowing connections from every IP. Atlas only accepts standard client connections from addresses included in that list. (MongoDB Atlas connection prerequisites)<br>From the Atlas cluster’s Connect window, I copied the driver connection string. Its general format was:<br>mongodb+srv://:@/<br>I used that URI to create a connection in VisuaLeaf and named it MongoDB Atlas. I tested the connection before continuing.<br>Creating the sync job<br>I opened Mongo Sync and created a new job with these details:

Setting<br>Value

Job name<br>Local Visits to Atlas

Description<br>Copy local clinic visits to Atlas and keep later changes synchronized.

Source connection<br>Local Replica Set

Source database<br>database_compare_demo

The source connection showed full change-stream support, which meant I could select Full sync later.<br>The local replica set and database_compare_demo database selected as the source.Mapping the local collection to Atlas<br>In the Rules step, I added the Atlas connection as the target and configured one rule:

Setting<br>Value

Target connection<br>MongoDB Atlas

Target database<br>database_compare_demo

Source collection<br>visits

Target collection<br>visits_atlas_sync

Filter<br>Empty

Transformation<br>None (pass-through)

I left the filter empty because I wanted all seven documents.<br>I also used None (pass-through) instead of generating field mappings. Both sides were MongoDB, so I wanted to preserve each document exactly as it was, including its _id, nested objects, arrays, dates, and optional fields.<br>Field mappings are useful when renaming fields, changing types, masking values, or sending data into a different schema. They were unnecessary for this direct MongoDB-to-MongoDB copy.<br>The visits collection mapped to visits_atlas_sync with pass-through documents.Choosing Full sync<br>The Options step offered three modes:

Mode<br>What it does<br>When to use it

Initial Only<br>Copies the documents that currently exist, then...

atlas mongodb local collection connection sync

Related Articles