DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk10 min

How to Import and Export a MongoDB Database

A practical guide to moving MongoDB data: choose BSON dump and restore for high-fidelity backups, or JSON, CSV, and TSV tools for collection-level interchange.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use MongoDB’s separate Database Tools from your operating system’s command line. Choose mongodump and mongorestore for a BSON-preserving database backup or migration; choose mongoexport and mongoimport when JSON, CSV, or TSV must move between MongoDB and another system. The right workflow depends on whether you need recovery fidelity or interchange convenience.

All examples below use a connection URI. Replace the user, password, host, database, collection, and file paths with values for your deployment, and test the procedure against a non-production copy before relying on it for a migration or restore.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Which MongoDB tool should you use?

MongoDB Database Tools are command-line utilities installed separately from the MongoDB server and shell. The four commands have different jobs, so selecting the pair first prevents an export that cannot later serve as a proper backup.

Goal Command pair Data format Best fit Important limitation
Back up or move a complete database mongodump → mongorestore Binary BSON Disaster recovery, server-to-server moves, and high-fidelity MongoDB transfers Source and destination must use the same major MongoDB version or the same feature compatibility version; encrypted collections have additional restrictions
Exchange one collection with another application mongoexport → mongoimport Extended JSON ETL pipelines, scripts, and application-to-application transfer A text export is not a complete database backup and may require explicit handling of BSON types
Work with spreadsheets or tabular tools mongoexport → mongoimport CSV or TSV Flat records and selected fields CSV and TSV do not retain MongoDB type information; an explicit field list is required for CSV export
Move a self-hosted deployment to Atlas Usually mongodump → mongorestore BSON archive or dump directory A documented Database Tools migration route Authentication, network access, version compatibility, and encrypted-collection support must be checked first

A BSON dump is the safer choice when the word “backup” means that you may need to reconstruct MongoDB data with its native types. JSON is the practical text choice when another program must read the output. CSV and TSV are useful only when a flat, column-oriented representation is acceptable.

#1 Best Overall
Sale
TOZO A1 Wireless Earbuds Bluetooth 5.3 Light Weight in Ear Headphones | IPX5 Waterproof,2 Mics for AI Calls,Immersive Premium Sound Bass Headset with Charging Case,32 EQ via App Black
  • [Ultra-Lightweight Ear Buds Designed for Small Ears] Each earbud weighs only 3.7g and features a compact, ergonomic in-ear design made especially for small ears. Secure, low-profile, and comfortable for workouts, all-day wear or overnight sleeping.The ultra-slim profile sits flush in your ear with no hard edges poking or rubbing, so you can even sleep on your side without discomfort.
  • [Immersive Stereo Sound with TOZO OrigX Technology] TOZO OrigX tuning delivers clear vocals, balanced mids, and natural stereo sound for music, podcasts, and videos.
  • [Long Battery Life for Daily Use] Get up to 7 hours of playtime on a single charge, with up to 32 hours total using the charging case—ideal for workdays, commuting, and extended listening sessions.
  • [Bluetooth 5.3 & Stable Connection] Bluetooth 5.3 provides fast pairing, stable wireless performance, and reduced dropouts as you move around home or office.
  • [Deep Bass with Clear Vocals] High-performance drivers produce punchy bass while keeping vocals clean and detailed for everyday listening.

Prepare the workstation and connections

Install and verify the Database Tools

Download the standalone MongoDB Database Tools package from MongoDB’s Download Center and install it on the machine that will run the transfer. The tools are not commands inside mongosh; run them from a system terminal such as PowerShell, Command Prompt, Bash, or a Unix shell.

  1. Install the package appropriate for your operating system and CPU architecture.
  2. Ensure the directory containing the executables is on your PATH, or open a terminal in that directory.
  3. Check the installed version:
mongodump --version

Run the same check for mongorestore, mongoexport, and mongoimport if more than one tools installation exists. Accidentally invoking an older executable is a common cause of confusing option or compatibility errors.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Collect the details the command needs

  • The source and destination connection URIs, including the correct port and authentication database when your deployment requires one.
  • A user with read access for an export or dump, and a user with the required write and database privileges for an import or restore.
  • A destination directory with enough free space for the dump, or enough room for an archive stream and temporary files.
  • The database and collection names, including exact capitalization.
  • A maintenance window or a consistency plan if writes will continue while data is copied.

Do not leave a real password in shell history, process listings, tickets, or scripts committed to source control. Prefer an interactive password prompt or a protected configuration mechanism supported by your environment. The examples show a password placeholder only to make the URI shape clear.

Back up a database as BSON with mongodump

mongodump creates a binary BSON representation intended for MongoDB restoration. It is the normal starting point for a database backup or a migration where preserving MongoDB’s native representation matters more than producing human-readable files.

Create a directory dump

mongodump --uri="mongodb://user:password@host:27017/db" --out ./dump

The command connects to the database named in the URI and writes a dump directory below ./dump. Keep the output directory intact: the BSON files and accompanying metadata are used together by mongorestore. If your URI contains characters that have special meaning to the shell or URI syntax, escape them according to your shell and connection-string rules.

Rank #2
Sale
Smart Watch for Men Women Compatible with iPhone Samsung Android Phone 1.69 inch Full Touch Screen IP68 Waterproof Bluetooh Fitness Tracker Heart Rate/Sleep Monitor (Black)
  • 【IP68 Waterproof Multifunctinal Smart Watch】Torjalph fitness activity tracker smart watch is IP68 waterproof technology ,you can wear it when swimming,handwashing,it's rain-proof which means that you perform multiple exercise modes outside without worrying about sweat or rain corroding your fitness smart watch,and this watch equipped with a 230 mAh large capacity battery magnetic charging ,and this sports activity tracker watch can be used 5-7 days If fully charged.
  • 【Larger 1.83'' Full Screen Watch & Multi-dial Selection】1.83 inch full HD color touch screen smart watch for men / women provides excellent 240*284 resolution image quality ,This Bluetooth smart watch offers a better touch experience and remarkable immersion and ,more than 200 watch faces for you to choose from App"Da Fit ", you can change the dial style according to your mood to wear keeping the world on your wrist
  • 【Accurate Activity Tracker Smart Watch 】sports watch activity tracker uses sweat and dust resistant breathable silicone strap, our Fitness Tracker Smart Watch for Android iOS Phones supports 12 sports modes,walking,running,bicycle,swimming,badminton,basketball,football,rope skipping. This bluetooth calls smart watch for men women is lightweight and stylish, bringing more convenient and relaxing sports experience while also providing more protection.
  • 【Your 24 Hour Personal Daily Health Monitor】Fitness watch for women men full touch screen IP67 waterproof bluetooth smartwatch for Android iOS Phones with heart rate blood pressure monitor multifunction Andriod smart watch with steps counter sleep monitor sports fitness watch, monitoring blood oxygen saturation allows you to understand your physical condition in real time to track fitness progress ,to know your health status in time.
  • 【More Functions Bluetooth Call Smart Watch】This fitness activity smart watch full screen for iPhone and Android phones includes a bunch of new features including:The bluetooth smart watch can hang up the phone, receive and display WhatsAPP /Text /Facebook /Twitter /Messenger reminder.Support sedentary reminder, alarm clock, stopwatch, timer,weather information,music control, remote camera control compatible with Android 5.0 and above or iOS 9.0 and above smartphones.

Stream a dump as an archive

For a direct server-to-server move, a dump can be piped into a restore without creating a persistent directory:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
mongodump --uri="mongodb://source:27017/db" --archive | mongorestore --uri="mongodb://target:27017" --archive

An archive is also convenient for moving one file through controlled storage. Treat it as sensitive database content and protect it with the same access controls as the live database.

What BSON preserves—and what it does not solve

BSON is the fidelity-oriented workflow because it remains in MongoDB’s native data model instead of flattening every value into text. It is therefore preferable to CSV when dates, object identifiers, arrays, nested documents, or other BSON-specific values must survive a transfer. It should not be confused with a universal snapshot of every deployment feature: mongorestore cannot be used with collections that use Queryable Encryption or client-side field-level encryption (CSFLE).

Restore a BSON dump with mongorestore

The restore program loads data from a binary database dump created by mongodump, or from standard input, into a mongod or mongos instance. A basic restore looks like this:

mongorestore --uri="mongodb://target:27017" ./dump

When the dump contains a database directory, the target URI does not need to name that database; the dump’s namespace information determines where its collections are restored. Confirm the resulting namespaces before allowing an automated job to run unattended.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
New Bee Guitar Cable 10ft Electric Instrument Bass AMP Cord
  • [Low Noise High Fidelity] New bee guitar cord with 22AWG oxygen-free-copper center conductors provides enhanced signal transfer, the PVC insulation material and the high-density stranded copper double shield provide noise rejection for quiet operation
  • [Ideal for Choice] New bee 1/4 straight and right angle metal connectors, ensures a secure connection in any instrument, pedal, or amp jack. L shape great fro on stage guitar stands
  • [Wide Compatible] Suitable for mixer, power amplifier, microphone, effector, decoder, equalizer, electoronic organ, electric guitar, electric bass and other electronic equipments. Widely used in the installation of smart home, karaoke speaker, professional stage audio, etc
  • [Easy Disassemble] Making incidental repairs quick and easy! Very nice, flexible cable
  • [Dont Hesite to Order] 24 hours customer services and professional technology team are standing by

Check compatibility before production

For BSON restores, the source and destination should use the same major MongoDB version or the same feature compatibility version. Check both deployments, rehearse the restore on a staging target, and verify application behavior before the production cutover. A restore that completes technically can still expose version-dependent behavior, missing privileges, or an application expecting indexes or validation settings that were not tested.

Understand the destructive effect of --drop

Use --drop only when you intentionally want the destination collections represented in the backup removed before their replacement data is restored:

mongorestore --uri="mongodb://target:27017" --drop ./dump

This is not a general “make the destination clean” switch. It affects collections represented in the backup, so review the dump scope and the target namespace first. Without deliberate approval, omit it and preserve existing collections.

Validate the restore

  • Inspect that the expected databases and collections exist.
  • Compare representative document counts and sample documents with the source.
  • Exercise application reads and writes using a least-privilege test account.
  • Check any indexes, validation behavior, users, and operational settings your application depends on.
  • Record the exact tool versions, command options, target URI, and restore time for auditability.

Export and import JSON

mongoexport and mongoimport operate primarily at collection scope. They are appropriate when a human-readable or machine-interchangeable file is more useful than a native backup.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Export a collection

mongoexport --uri="mongodb://user:password@host:27017/mydb" 
  --collection=users --out=users.json

By default, mongoexport writes Extended JSON v2.0 in relaxed mode. Relaxed Extended JSON is convenient to read, but it is not always the best representation for a round trip in which every BSON type must remain unambiguous.

Rank #4
BSIMB 15.6" Digital Family Calendar & Chore Chart, No Subscription Fees
  • Digital Family Calendar: BSIMB digital calendar wall touch screen puts an end to your chaotic life. Designed for busy families, the digital calendar keeps you organised and in step with your family. Assign different colours and tasks to each family member to make family scheduling easier and more intuitive.
  • Easy Setup and Auto-Sync: Plug in, connect to WLAN and auto-syn your electric calendar in minutes. Digital wall calendar compatible with Google calendar, iCloud calendar, Outlook calendar, Cozi calendar and Yahoo calendar. Add events directly on the device or through the ecalendar app. Electronic calendar stays current whether you're at work or traveling—no manual updates needed.
  • All-In-One Home Assistant: Smart calendar builds habits and encourage independence with personalised chores. Display daily meal plan to reduce the daily ‘What's for dinner?’ stress. To-do lists keep track of everything you want. Turning chores into valuable achievements with stars and rewards, making life easier and more enjoyable.
  • Manage Anytime Anywhere: BSIMB electronic calendar for family stay connected with the powerful ecalendar app. Access and manage your digital wall calendar anytime, anywhere with free features like stars & rewards, photo screensaver, chore charts, meals plans, to-do lists etc. Electronic planner paid features like Magic Import tailor advanced tools for users with special needs.
  • Stay in Touch with Loved Ones: Share photos or videos from your phone to electronic wall calendar with app, instantly update your life moment, and keep in touch with your family, especially those who are far away; you can also surprise your smart calendar digital wall by sending him a wish card; it's also great for keeping tech-illiterate elders in touch with the youngsters.

Use canonical Extended JSON when types matter

mongoexport --uri="mongodb://host:27017/mydb" 
  --collection=users --jsonFormat=canonical --out=users.json

Canonical mode is the text-oriented choice when preserving rich BSON values is important. MongoDB-specific values such as dates need Extended JSON notation; for example:

{ "$date": "2019-12-01T00:00:05.5640Z" }

mongoimport detects the JSON format in the input file. Import a collection with:

mongoimport --uri="mongodb://user:password@host:27017/mydb" 
  --collection=users --file=users.json

A JSON file is still not equivalent to a full database backup. It is collection-oriented interchange data and should not be your only copy when disaster recovery, database-wide metadata, or native fidelity is the requirement.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Account for field-name ambiguity

Field names beginning with $ or containing . create documented import and export conflicts. Extended JSON also cannot distinguish some type-wrapper names from literal field names that begin with $. If your schema permits such names, inspect a representative export and choose a format and transformation strategy that cannot reinterpret them.

Exchange data as CSV or TSV

CSV and TSV are useful for flat records, spreadsheets, and systems that do not understand JSON. They deliberately trade MongoDB’s type system for broad compatibility.

Export selected fields to CSV

CSV export requires an explicit field list:

mongoexport --uri="mongodb://host:27017/mydb" 
  --collection=contacts --type=csv 
  --fields="name,address" --out=contacts.csv

List only fields that have a predictable tabular shape. Nested documents and arrays may need a transformation before a spreadsheet or relational importer can use them safely.

Import a CSV header row

mongoimport --uri="mongodb://host:27017/mydb" 
  --collection=contacts --type=csv 
  --headerline --file=contacts.csv

--headerline tells the importer to use the first row as field names. For tab-separated input, replace --type=csv with --type=tsv. Because CSV and TSV carry no MongoDB type information, values that must become dates, numbers, object identifiers, or other specific types need explicit type handling rather than an assumption that the importer will infer the intended schema.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Periods in CSV field names can be interpreted as hierarchy separators, and field names beginning with $ can conflict with MongoDB’s notation. Normalize or rename headers before import when those characters are part of literal field names.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Update existing documents with upsert mode

A normal import is aimed at loading documents. If the job should update a matching document when one exists and insert it when it does not, use upsert mode:

mongoimport --uri="mongodb://host:27017/mydb" 
  --collection=users --file=users.json 
  --mode=upsert --upsertFields=email

Without --upsertFields, matching uses _id by default. Supplying email changes the matching key to that field. Before running this against production, confirm that the chosen field is stable and uniquely identifies a document; otherwise, records can be updated unexpectedly or collide.

Move a self-hosted deployment to MongoDB Atlas

MongoDB documents the Database Tools as one route for migrating a self-hosted deployment to MongoDB Atlas. The practical pattern is to create a BSON dump from the source and restore it into the Atlas connection string, either from a dump directory or through an archive stream.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Create an Atlas target and obtain its connection URI.
  2. Allow the migration machine to reach the Atlas network endpoint and configure an Atlas database user with the required privileges.
  3. Check source and target MongoDB versions or feature compatibility settings.
  4. Run mongodump against the self-hosted source.
  5. Run mongorestore against Atlas, omitting --drop unless replacement is intentional.
  6. Validate counts, representative documents, indexes, application queries, and write behavior before directing application traffic to Atlas.

This tools-based approach is a transfer procedure, not an automatic zero-downtime replication plan. If the source continues to receive writes during the copy, define how you will capture or reconcile changes and schedule the final cutover accordingly.

Operational safety checklist

  • Use the system shell: these executables are not mongosh commands.
  • Protect credentials: avoid exposing passwords in command history and process listings.
  • Confirm permissions: exports require read access; restores and imports require suitable write privileges.
  • Confirm namespaces: check the database and collection names before writing to a shared target.
  • Check compatibility: match major MongoDB versions or feature compatibility versions for BSON restores.
  • Choose the format deliberately: BSON for fidelity, Extended JSON for text interchange with BSON awareness, and CSV/TSV for flat tabular exchange.
  • Review destructive flags: treat --drop as an intentional replacement operation, not a routine default.
  • Test recovery: a backup is useful only if a restore has been rehearsed and verified.
  • Consider encryption features: Queryable Encryption and CSFLE collections cannot be restored with mongorestore.
  • Inspect unusual field names: leading dollar signs and periods can change how importers interpret fields.

Troubleshoot the most common failures

Symptom Likely cause What to check
“Command not found” or an unrecognized option The Database Tools are not installed, are missing from PATH, or an old executable is being called Install the standalone package and run mongodump --version using the intended executable
Authentication failure Wrong credentials, authentication database, or insufficient role Test the URI separately, verify the user’s privileges, and avoid embedding a mistyped password in scripts
Connection timeout Firewall, DNS, TLS, VPN, or Atlas network access configuration Confirm the host and port are reachable from the machine running the tool and that the deployment allows its source address
Restore refuses to run or reports incompatibility Different major versions or feature compatibility settings Check both deployments and rehearse with compatible versions before the production restore
Documents import with wrong types Relaxed JSON, CSV, or TSV cannot express the intended BSON type unambiguously Use canonical Extended JSON for a text round trip, or use BSON dump/restore when native fidelity is required
Fields are renamed, rejected, or nested unexpectedly Field names contain $ or ., or CSV parsing treats periods as hierarchy separators Rename or transform those fields and inspect a small test import before the full run
Existing records are duplicated The import is not matching on the intended key Use --mode=upsert with a stable --upsertFields value, or match on _id deliberately
Target data disappeared --drop was used on a restore Stop further writes, identify the affected namespaces, and recover from a verified backup; use --drop only for planned replacement restores

A practical selection guide

Choose mongodump and mongorestore when

  • You are creating a disaster-recovery backup.
  • You need to move a database between MongoDB deployments.
  • Preserving BSON values is more important than opening the file in a spreadsheet.
  • You can satisfy version, authentication, network, and encryption constraints.

Choose mongoexport and mongoimport when

  • Another application, script, or analyst needs JSON, CSV, or TSV.
  • You are moving a specific collection rather than reconstructing a complete database.
  • You understand which BSON types the destination can represent.
  • You need upsert matching against a field such as email.

Use a two-stage workflow when necessary

It is reasonable to keep a BSON dump as the recovery copy and produce a separate JSON or CSV export for an integration. Do not substitute the integration file for the recovery copy: the convenient interchange format may omit type information, database-wide metadata, or structures required for a faithful restore.

End-to-end command checklist

  1. Install the Database Tools and verify their version.
  2. Test source and target URIs and confirm the required roles.
  3. Decide whether fidelity or interoperability is the primary requirement.
  4. For a backup or migration, run mongodump; for a collection interchange, run mongoexport.
  5. Inspect the generated files and record the namespace, format, and tool version.
  6. Restore with mongorestore, or import with mongoimport, on a staging target first.
  7. Validate counts, sample values, types, application behavior, and any intended upsert results.
  8. Only then schedule the production cutover or retain the output as an operational backup.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.