mongorestore file X does not have .bson extension
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
mongorestore expects a dump produced by mongodump, and that means BSON collection files plus optional metadata files. If it reports that file X does not have .bson extension, it is telling you that something in the restore path is not a valid dump file for directory-based restore.
In practice, this error usually comes from one of three causes: a stray file in the dump directory, using the wrong tool for JSON data, or passing an archive file without the --archive mode.
What mongorestore Expects
When restoring from a directory, mongorestore scans for files that look like collection dumps:
- '
collection.bson' - '
collection.metadata.json'
A typical dump created by mongodump looks like this:
This works:
If the directory also contains unrelated files such as .DS_Store, README.txt, or exported JSON files, mongorestore may complain when it encounters them.
The Most Common Real Causes
The first common cause is an extra file in the dump tree. For example, macOS often leaves .DS_Store files in folders, and backup tooling may create sidecar files that mongorestore does not know how to interpret.
The second cause is using JSON export data. If the file came from mongoexport, then mongorestore is the wrong tool entirely. mongoexport and mongoimport work with JSON or CSV. mongodump and mongorestore work with BSON dump format.
The third cause is archive mode confusion. If you created a single archive file with mongodump --archive, you must restore with mongorestore --archive, not by pointing mongorestore at the file as though it were a dump directory.
Fix 1: Clean the Dump Directory
Inspect the directory first:
If you see non-dump files mixed into the restore path, remove or relocate them before restoring:
Then rerun:
This is the simplest fix when the dump itself is valid and only the directory contents are noisy.
Fix 2: Use the Right Tool for JSON
If the file is JSON, do not rename it to .bson. That will not convert the format.
Use mongoimport instead:
Renaming a JSON file to users.bson only changes the filename, not the binary format that mongorestore expects.
Fix 3: Use Archive Mode Properly
If the backup was created as an archive:
Restore it like this:
Do not point mongorestore at backup.archive as though it were a directory of .bson files. The restore mode has to match the dump mode.
Verify the Backup Type Before Restoring
A good habit is to check how the backup was created before choosing the restore command:
- '
mongodumpoutput directory meansmongorestore <directory>' - '
mongodump --archivemeansmongorestore --archive' - '
mongoexportJSON meansmongoimport'
Once you keep those pairings straight, this error becomes much easier to avoid.
Common Pitfalls
The most common mistake is assuming any MongoDB backup-like file can be fed to mongorestore. The tool only understands specific dump formats.
Another common issue is leaving unrelated files in the dump directory. A restore tree should be clean, especially when it is copied between systems or extracted from archives.
People also rename files by hand, thinking the extension alone is the format. A .bson filename does not make a JSON file into BSON data.
Finally, archive mode and directory mode are different workflows. If the backup was created with --archive, restore it with --archive.
Summary
- '
mongorestoreexpects BSON dump files frommongodump, not arbitrary files.' - Extra files in the dump directory can trigger the
.bson extensionerror. - JSON exports belong to
mongoimport, notmongorestore. - Archive dumps must be restored with
mongorestore --archive. - Check the actual backup format before trying to fix the restore command.
Related reading
- monk vs mongoose for Mongodb
- Most efficient way to check for DBNull and then assign to a variable?
- Moving data from Snowflake to Kafka
- MS-SQL Server 2005 Initializing a merge subscription with alternate snapshot location
- More than one fragment with the name spring_web was found. This is not legal with relative ordering
- Most pythonic way to delete a file which may not exist
- MSSQL - replication and Violation of PK constraint
- Multi-Source Replication on MySQL

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.