Registry / database / mongodb-restore-dump

mongodb-restore-dump

JSON →
library1.0.1jsnpmunverified

Simple Node.js library to restore MongoDB dumps from BSON files created by mongodump. Version 1.0.1 is the latest stable release (no update cadence documented). Key differentiator: programmatic API for restoring dumps (full dump, single database, or single collection) with optional collection cleaning before insertion. Compared to mongorestore CLI, this lib offers fine-grained control within Node.js scripts. Minor downloads and single maintainer.

npm install mongodb-restore-dump
INSTALL
IMPORT
SIG · MONGODB-RESTORE-DU
M
mongodb-restore-dump
databasejavascriptv1.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (restore object)
const restore = require('mongodb-restore-dump')
import restore from 'mongodb-restore-dump'
This package exports a single default export as an object with methods dump, database, collection. ESM import may fail due to lack of default ESM export.
restore.dump
const { dump } = require('mongodb-restore-dump')
const { dump } = await import('mongodb-restore-dump')
Destructuring works in CJS. ESM dynamic import yields a module namespace object; destructuring works but not default import.
restore.database
const { database } = require('mongodb-restore-dump')
Same pattern as above.

Demonstrates restoring full dump, single database, and single collection from BSON files with optional clean and limit.

const restore = require('mongodb-restore-dump'); async function main() { const uri = process.env.MONGO_URI || 'mongodb://127.0.0.1:27017/'; // Restore entire dump from directory await restore.dump({ uri, from: './dumps/mydump/', clean: true }); // Restore single database await restore.database({ uri, database: 'mydb', from: './dumps/mydump/mydb/', clean: false }); // Restore single collection with limit await restore.collection({ uri, database: 'mydb', collection: 'mycoll', from: './dumps/mydump/mydb/mycoll.bson', limit: 100 }); } main().catch(console.error);
Debug
Known issues
breakingThe default value for 'clean' is true; collections will be dropped before restore unless explicitly set to false.
fix
Set clean: false if you want to append documents instead of replacing.
affects: <=1.0.1
deprecatedThe package uses mongodb driver v3 style (MongoClient.connect callback) internally; may break with newer driver versions.
fix
No fix provided by maintainer; consider migrating to mongodb driver v4+ and adapt code.
affects: <=1.0.1
gotchaThe 'con' parameter expects an existing MongoDB connection, but if both 'uri' and 'con' are omitted, the library does not create one and will throw.
fix
Always provide either 'uri' or 'con'.
affects: <=1.0.1
gotchaThe 'from' path must point to the exact directory or file; trailing slash behavior not documented.
fix
Use absolute paths or ensure relative paths are correct relative to process.cwd().
affects: <=1.0.1
Errors
Common errors & fixes
TypeError: restore.dump is not a function
Incorrect import: using ESM default import on a CJS module.
fix
Use const restore = require('mongodb-restore-dump') or dynamic import with .default.
MongoError: command find requires authentication
URI missing credentials or user lacks permissions.
fix
Include credentials in URI: mongodb://user:pass@host:port/db
Error: ENOENT: no such file or directory, open './dumps/mydump/mydb.bson'
The 'from' path is incorrect or the BSON file does not exist.
fix
Verify the dump directory structure; ensure the path points to the directory (for database) or .bson file (for collection).
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
mongodbrequiredOfficial MongoDB driver for database operations
Agent activity
6 hits · last 30 days
node
6
Resources
mongodb-restore-dump — npm install mongodb-restore-dump · libregistry