Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
VGSources
Blog

How to Import and Export a MongoDB Database

A practical MongoDB import and export guide covering BSON backups, JSON and CSV interchange, restores, upserts, version compatibility, encryption limits, troubleshooting and Atlas migration.
Length10 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use MongoDB’s 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 another system needs JSON, CSV, or TSV. The right workflow depends on whether you need MongoDB fidelity, broad interoperability, a whole database, or selected collections.

Choose the tool before you move any data

MongoDB ships its command-line utilities as the separate Database Tools package. They are not commands inside mongosh. Install the package on the computer that will perform the transfer, open your operating system’s terminal or command prompt, and verify the installation:

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.
mongodump --version

There are two fundamentally different workflows:

Goal Export tool Import or restore tool Data representation What it is best for
Backup, disaster recovery, or a MongoDB-to-MongoDB move mongodump mongorestore Binary BSON dump Retaining MongoDB data types and restoring a database or selected namespaces
Exchange data with applications, ETL jobs, or other databases mongoexport mongoimport Extended JSON, CSV, or TSV Human-readable files and interoperability

A text export is not a substitute for a complete disaster-recovery backup. JSON, CSV, and TSV do not necessarily retain indexes, validation rules, or every BSON type. Use the BSON workflow when the destination must behave like the source MongoDB deployment.

Prepare the source and destination

Install and check the Database Tools

Download the Database Tools package from MongoDB’s Download Center, install it, and ensure the directory containing the executables is on your PATH or that you run the commands with their full path. Check the version from the same terminal session that will run the transfer. The utilities should be run from the system shell, not from a MongoDB shell prompt.

#1 Best Overall
Sale
Gaoye Blue Light Blocking Glasses
  • BLUE LIGHT BLOCKING GLASSES: Our blue light glasses for women boast UV400 protection, blocking harmful blue rays from computer screens. With these bluelight glasses women, you can enjoy gaming, reading, or watching TV with no worries of eye strain.
  • EYE RELIEF: Our blue light glasses are engineered to reduce blurry vision or strain caused by prolonged screen time. These womens blue light glasses aid in better sleep by preventing blue light from disrupting your natural sleep cycle, helping you fall asleep faster and enjoy a more restful night's sleep, making them the perfect christmas present.
  • COMFORTABLE: Crafted from durable material, our trendy blue light glasses for woman or blue light glasses men ensure long-lasting comfort. The high-transmittance lenses accessories, gamer gifts for men, help keep your eyes relaxed. Perfect stocking stuffers, gifts for gamers men, christmas gifts for men, halloween costumes.
  • LIGHTWEIGHT: These clear blue light glasses feature a lightweight frame, meaning they’ll stay comfy for long-term wear. Perfect as blue blockers glasses for women or mens blue light glasses, these non-prescription fake glasses for men can be worn throughout the day. The blue light blocking glasses women feature polycarbonate HD lenses, which are anti-reflective and restore true color.
  • WORRY-FREE PURCHASE: If you experience any issues, our support team is ready to assist you quickly. These are the perfect costume glasses for cosplay dressing up.

Confirm network access and permissions

  • The machine running the command must be able to resolve and connect to the source or destination host and port.
  • The account used for an export needs read access to the database being exported.
  • A restore account needs the permissions required to create or replace the target databases and collections.
  • For a hosted deployment, allow the client machine through the service’s network controls before testing the command.

Test credentials and connectivity with a small, non-production operation before starting a full transfer. A URI that includes a password is convenient for examples but can expose the secret in shell history or process listings. Prefer an interactive password prompt or a protected configuration file in operational scripts, and restrict permissions on any file containing credentials.

Check version compatibility for BSON restores

For mongorestore, the source and destination must use the same major MongoDB version or the same feature compatibility version. Confirm that compatibility before the production restore, not after a dump has been copied to the target. Keep the Database Tools version and the server versions documented with the backup so a later recovery does not depend on guesswork.

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.

Back up a database with mongodump

mongodump creates a binary BSON dump. BSON retains MongoDB-specific values more faithfully than CSV and is the normal choice for a MongoDB-to-MongoDB move.

Write a directory dump

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

This command connects to the named database and writes a directory tree under ./dump. Use a destination with enough free space for the dump and any temporary files. Treat the resulting directory as sensitive: it contains the database’s data and should be protected with the same care as the live deployment.

Stream a dump as an archive

When you do not need an intermediate directory, pipe an archive directly to mongorestore:

mongodump --uri="mongodb://source:27017/db" --archive | mongorestore --uri="mongodb://target:27017" --archive

The pipeline avoids manually copying a dump directory, but it also means a failure in either command interrupts the transfer. For a high-value migration, capture the terminal output, monitor the exit status of the pipeline in your operating system, and perform a verification query on the target afterward.

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

Limit the scope deliberately

A dump can represent an entire database or a narrower selection of namespaces, depending on the options you supply. Decide whether the target should receive every collection or only selected collections before running the command. Record the URI, database name, collection filters, tool version, and time of the dump with the backup so another operator can reproduce the intended scope.

Rank #2
Windex Gaming Cleaning Wipes, Pre-Moistened Wipes to Instantly Clean all Gaming Gear and Electronics, Resealable Packaging for a Freshness Lock, 25 count (Pack of 1)
  • WINDEX GAMING WIPES: effortlessly clean all your gaming gear and gaming electronics in one easy step with our new Windex Gaming Wipes
  • AMMONIA FREE: our ammonia-free formula is safe to use on all of your favorite gaming equipment like consoles, headsets, controllers, screens, keyboards, and more
  • PRE-MOISTENED WIPES: each wipe instantly removes dust, dirt, and stubborn smudges and fingerprints leaving a streak-free shine
  • ANTI-STATIC: great for cleaning and wiping down your gaming gear and electronics leaving behind no visible residue
  • COMPACT RESEALABLE PACKAGE: store your pack of Windex Gaming Wipes anywhere in your home for whenever a quick and easy wipedown is needed

Restore BSON with mongorestore

MongoDB documents mongorestore as loading data from a binary dump created by mongodump or from standard input into a mongod or mongos instance. A directory restore uses the dump path:

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

An archive restore uses standard input or an archive file:

mongorestore --uri="mongodb://target:27017" --archive

The second command expects archive bytes on standard input, as in the streaming example above. If you saved an archive to disk, provide the archive file according to the Database Tools option syntax installed on your system.

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

Decide whether to use –drop

Adding --drop tells mongorestore to drop each target collection represented in the backup before restoring that collection. This is appropriate only when the target is intentionally being replaced. It can destroy newer target data, so do not add it as a routine troubleshooting step. Without that option, existing target content is not automatically treated as a clean replacement.

Validate a restore

  1. Confirm that the target server is the intended host and that its MongoDB version or feature compatibility version meets the BSON requirement.
  2. Run a restore in a staging database or isolated deployment first when the data is important.
  3. Check that expected databases and collections exist and that representative document counts and values match the source.
  4. Test application reads and writes against the restored data before directing production traffic to it.
  5. Record any intentionally omitted namespaces, authentication changes, or post-restore repairs.

Queryable Encryption and client-side field-level encryption (CSFLE) collections cannot be restored with mongorestore. Plan a supported application-level or service-specific migration for those collections rather than treating a normal BSON restore as a solution.

Export MongoDB data to JSON

mongoexport is collection-oriented. Supply a URI, database, collection, and output path:

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

By default, mongoexport writes Extended JSON v2.0 in relaxed mode. This is convenient for many integrations, but relaxed output is not the best choice when a downstream process must preserve the exact BSON types.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
LISEN Cell Phone Stand Phone Holder for Desk, Office Decor Gadgets for Men
  • Ergonomic & Adjustable Design: Fight "text neck" and improve your posture. Designed for comfort, it offers an adjustable height (7.1in-8.5in) (1.4in adjustable range) and angle (5°-85°) Please note: cell phone stand is only 9 inches tall—the length of a standard pencil
  • Without blocking subtitles Perfect for office desk Tiktok Face Time Zoom video—this is the ultimate kitchen desk essential for phones! Perfect viewing experience while reducing neck back strain, A must-have for gamers streamers desk, and anyone who values both style and support!
  • Sleek & Stable Design fits Otterbox Case: Say goodbye to bent cables, tangles, and tip-overs! LISEN’s stylish adjustable desk phone holder features a built-in charging hole and smart cable management, keeping your phone secure and your workspace clutter-free cool gadgets for men
  • ANTI-SLIP DESIGN free hands: The under 10.00 items easy gadgets back and the bottom of this kitchen essentials for women are fully covered by anti-skid silicone, which LISEN stand up desk decor can provide maximum protection device from any scratches and slides
  • Your Perfect Viewing Companion:If your product arrives damaged or breaks within 365 days, reach out to LISEN for a quick and hassle-free solution. Struggling with assembly, like tightening the screw? We’ve got your back! Your experience matters to us. (Product including: phone Holder stand*1, screw*1, hexagon screwdriver*1, specification*1)

Use canonical Extended JSON when types matter

For a text representation that retains MongoDB type information more explicitly, request canonical format:

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

Extended JSON is required for MongoDB-specific values such as dates. For example, a date may appear as:

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

When importing, mongoimport detects the JSON format in the file. Keep the format choice documented with the file so a consumer does not mistake a typed value for an ordinary string.

Import JSON with mongoimport

Import a JSON collection with:

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

The destination collection must be chosen explicitly. A JSON file is a data interchange artifact, not a complete database definition: it does not by itself recreate every index, validator, or deployment setting from the source.

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

Update existing documents with upsert mode

By default, upsert matching uses _id. To match on another field, use --mode=upsert with --upsertFields:

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

In this example, an incoming document with an email value updates the matching target document or inserts a new one when no match exists. Choose a field whose values are stable and appropriately unique; otherwise, multiple incoming records can match the same target or create unintended duplicates.

Exchange data as CSV or TSV

CSV is useful for spreadsheets and systems that cannot consume BSON or Extended JSON, but it requires an explicit field list on export:

Rank #4
Ledagic IC+RGBW USB Powered Led Light Bar with App & Remote Control, 2 Pack
  • Easy Installation: Our gaming lights have been designed to enhance your entertainment experience. Simply position the led light bar next to your TV or game console to create a game room environment with ease. They come with USB power and a 60 inch cord for direct mounting and mobility
  • Audio Syncing & Extensive Mode: The built-in high-sensitivity music sensor allows you to sync the TV led lights to your favorite music. Lights react and move to the beat of music, film and game audio, creating an incredible immersive sound and light experience – and all without the need for an additional hub. You can choose from 64+ patterns, including strobe, illusion, jump, energy, gradient, running, chasing, fluttering mode etc. Each mode can be applied to different scenes
  • 64+ Chasing IC+RGB & W Effect: The independent control design of IC+RGB and white all-in-one multifunctional rgbw led bar lights monitor backlight allows you to easily switch the led lights for desk between IC+RGB and white to enjoy a variety of lighting effects, you can choose white lighting mode with high brightness for better illumination when working, etc. Choose IC+RGB lighting mode when you need to create an entertaining atmosphere for the light show, 16 million colours of Color changing rgb light bar let you dance to the beat and create a dynamic party atmosphere
  • Dynamic and Dimmable Lights: 1%-full brightness free brightness adjustment gives you the flexibility to adjust dimmable led light bar for room decorations or a variety of occasions
  • USB Powered: USB light bars for room can be powered by powernank, usb charger, TV, Monitor, laptop PC mainframe, making behind TV led lighting bar easy to install in any location.TV led lights are powered by the TV usb interface / PC mainframe, can be turned on/off synchronously with TV / PC
mongoexport --uri="mongodb://host:27017/mydb" 
  --collection=contacts --type=csv 
  --fields="name,address" --out=contacts.csv

Import a CSV file whose first row contains the field names with:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
mongoimport --uri="mongodb://host:27017/mydb" 
  --collection=contacts --type=csv 
  --headerline --file=contacts.csv

For tab-separated data, use --type=tsv instead. CSV and TSV do not carry MongoDB type information. Numbers, booleans, dates, arrays, and nested documents may need explicit type handling in the importing workflow. If preserving those values matters, use BSON or canonical Extended JSON instead of flattening the data into a delimited file.

Watch for field-name conflicts

Field names beginning with $ or containing a period have documented import and export conflicts. In CSV, periods can be interpreted as hierarchy separators, which can change how a column is mapped. Extended JSON also cannot distinguish some type-wrapper names from literal field names that begin with $. Review the schema for these names before selecting a text interchange format, and test a representative file rather than assuming a round trip will be lossless.

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 basic pattern is the same as any MongoDB-to-MongoDB move:

  1. Install the Database Tools on a machine that can reach the self-hosted source and the Atlas target.
  2. Confirm the Atlas network access rules and create a destination database user with the permissions required for the restore.
  3. Check source and target MongoDB versions or feature compatibility versions before creating a BSON dump.
  4. Create a directory dump with mongodump, or stream an archive directly into mongorestore.
  5. Restore into the Atlas connection string, initially using a staging or otherwise isolated target when possible.
  6. Validate collections, representative documents, indexes and application behavior before changing application connection settings.

For a large or continuously changing production database, a one-time dump introduces a point-in-time boundary: writes that occur after the dump begins are not automatically included. Plan an application pause, a controlled cutover, or another migration method appropriate to your recovery-point requirement rather than assuming the command alone provides zero downtime.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Common failure modes and fixes

“Command not found” or an unexpected version

The Database Tools are separate from the server and shell packages. Reinstall or correct the executable path, then run mongodump --version from the same terminal used for the transfer. If multiple installations exist, call the intended executable by its full path and remove ambiguity from automation.

Authentication or authorization errors

Check the username, authentication database, URI encoding, and the account’s permissions. An export requires read access on the target database. A restore requires write and database-management permissions appropriate to the operation. Avoid copying a password into logs while troubleshooting; use a prompt or protected configuration instead.

Best Value
Sale
HUANUO FlowLift™ Dual Monitor Stand, Fully Adjustable Gaming Monitor Desk Mount for 13–32″ Computer Screens, Full Motion VESA 75x75/100x100 with C-Clamp & Grommet Base, Each Arm Holds 4.4 to 19.8 lbs
  • Compatible with Wide Screens - To ensure compatibility with the dual monitor mount, your each monitor must meet three conditions at the same time: First, computer screens size range: 13 to 32 inches. Second, screen weight range: 4.4 to 19.8 lbs. Third, the back of the monitor screen must have VESA mounting holes with a pitch of 75x75mm or 100x100mm.
  • Regarding the compatibility with desks - Your desk must meet three conditions at the same time: First, desk material: Only wooden desks are recommended, plastic or glass desks cannot be used. Second, desk thickness range: 0.59" - 3.54". Third, the bottom of the desk should not have any cross beams or panels, as this will interfere with installation. We recommend carefully checking that your desk and monitors meets all above conditions before purchasing.
  • Dual C-Clamp Hold - Worried your dual monitors might wobble or slip? Our upgraded base uses a larger platform plus a dual C-clamp structure to lock the dual monitor arm firmly to your desk. Each arm safely keeps your screens steady while you type, click and game—no shaking, no sliding, just a clean and secure setup you can trust every day. It also provides Grommet Mounting installation choice, both options ensure stable and secure fixation for your 0.59" - 3.54" desk.
  • Full-Motion Adjustment For Comfortable View - Pull the screen closer when you’re deep in a spreadsheet, push it back to watch videos, or rotate to portrait for coding — moving everything smoothly with just one hand. The monitor stand offers +85°/-50° tilt, ±90° swivel and 360° rotation. Raise your monitor up to 15.75″ to support a healthy sitting posture. Whether you’re working from home, gaming through the night, or switching between video calls and documents, getting the screens to your natural line of sight helps relieve neck, shoulder and back strain so you can stay focused longer with less fatigue.
  • Keep Your Desk Organized: By lifting both screens off the desktop, this dual monitor stand opens up valuable space for your keyboard, notebook, docking station or a simple, clutter-free work area. Built-in cable management guides wires along the arms, keeping cords out of sight and out of the way. Enjoy a tidy, modern workstation that looks as good as it feels to use.

Connection timeouts

Verify DNS, the host and port in the URI, firewall rules, and hosted-service network allowlists. Test the connection from the machine running the utility, not from a different workstation that has different network access.

Version or feature-compatibility errors during restore

Compare the source and destination major versions or feature compatibility versions. A BSON dump is not a license to restore across incompatible server configurations. Align the versions, or use a migration plan that explicitly supports the difference.

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

Unexpected duplicates or overwritten documents

Review the import mode. Standard imports and upserts have different behavior, and upsert matching defaults to _id. If you supplied --upsertFields, verify that the selected field is stable and unique. Never add --drop merely to silence a conflict unless replacing the target collection is intentional.

Dates or numbers arrive as strings

This usually indicates that a CSV or relaxed text workflow discarded type information. Re-export using canonical Extended JSON, or define the conversion rules required by the receiving process. A date encoded with an Extended JSON wrapper such as { "$date": "2019-12-01T00:00:05.5640Z" } can be interpreted as a MongoDB date rather than ordinary text.

Encrypted collections will not restore

mongorestore cannot restore collections that use Queryable Encryption or client-side field-level encryption. Stop and select a migration path designed for that encryption configuration; repeatedly changing restore flags will not remove the limitation.

A safe runbook for production transfers

  1. Define the objective. Label the operation as disaster-recovery backup, full MongoDB migration, or text interchange. This determines the tool pair.
  2. Inventory the data. Note databases, collections, encryption features, unusual field names, indexes, validators, and the expected write activity during the move.
  3. Prepare tools and access. Install the Database Tools, verify the version, confirm connectivity, and test least-privilege credentials.
  4. Run a rehearsal. Export or dump a representative subset and restore or import it into an isolated target. Check types, counts, indexes, and application queries.
  5. Perform the production operation. Capture the exact command, time, source, destination, options, and terminal output. Protect the dump or text files.
  6. Validate independently. Compare representative documents and collection counts, exercise critical application paths, and inspect errors before cutover.
  7. Protect the rollback path. Keep the original source available until the new deployment is accepted, and retain the backup according to your recovery policy.

Which workflow should you use?

Requirement Recommended workflow Reason
Recover a database after data loss mongodump followed by mongorestore Binary BSON is designed for MongoDB restoration and preserves data more faithfully than delimited text.
Move a self-hosted database to another MongoDB deployment or Atlas BSON dump and restore, subject to version and encryption constraints It transfers MongoDB data without converting every value into a generic text type.
Send selected records to an external application mongoexport and the receiving system’s importer JSON is broadly consumable and can retain types when canonical Extended JSON is used.
Load a spreadsheet-shaped contact list CSV or TSV with an explicit schema review Delimited files are convenient, but they require field lists and do not preserve BSON types.
Merge incoming records into an existing collection mongoimport --mode=upsert with a deliberate matching field Upsert mode updates matches and inserts missing documents instead of treating every row as a new record.

The short rule is simple: use mongodump/mongorestore when MongoDB fidelity and recoverability matter; use mongoexport/mongoimport when a collection must cross a system boundary as JSON, CSV, or TSV.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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

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 quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
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.