Registry / storage / mongodb-backup

mongodb-backup

JSON →
library1.6.9jsnpmunverified

A Node.js library for creating backups of MongoDB databases by programmatically invoking mongodump-like functionality. Current stable version is 1.6.9, with a history of weekly or monthly releases. It supports streaming backups, tar packaging, collection selection, query filtering, and metadata preservation. Compared to direct mongodump usage, it provides a JavaScript API suitable for integration into build processes or deployment scripts. Requires Node >=4 and uses BSON for binary data serialization.

npm install mongodb-backup
INSTALL
IMPORT
SIG · MONGODB-BACKUP
M
mongodb-backup
storagejavascriptv1.6.9
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.

backup
const backup = require('mongodb-backup');
import { backup } from 'mongodb-backup';
This package uses CommonJS; default export is a function, not a named export.
backup
const b = require('mongodb-backup'); b({...})
import backup from 'mongodb-backup';
ESM default import may not work as expected; CommonJS require is recommended.
backup
const backup = require('mongodb-backup'); backup.default({...})
const { default } = require('mongodb-backup');
No default export property; the module exports the backup function directly.

Demonstrates how to perform a basic MongoDB backup using the mongodb-backup library, including URI authentication, collection filtering, query limitation, and JSON parser for readable output.

const backup = require('mongodb-backup'); const options = { uri: process.env.MONGO_URI || 'mongodb://localhost:27017/mydb', root: '/backup/mydb', collections: ['users', 'orders'], query: { active: true }, parser: 'json', callback: function(err) { if (err) console.error('Backup failed:', err); else console.log('Backup completed.'); } }; backup(options);
Debug
Known issues
deprecatedBson@0.4.11 has been pulled out, so versions >= 1.3.0 and <= 1.4.1 are deprecated.
fix
Upgrade to version >=1.5.0.
affects: >=1.3.0 <=1.4.1
gotchaThe module uses the BSON parser by default, which produces binary files. To get human-readable JSON output, you must set 'parser' option to 'json'.
fix
Add parser: 'json' to the options object.
affects: all
gotchaThe 'uri' parameter is required and must include authentication credentials if your MongoDB requires them; otherwise backup fails.
fix
Ensure your URI string includes username, password, host, port, and database name in the correct format.
affects: all
breakingVersion 1.5.0 changed the 'root' option behavior: backups are now saved in a subdirectory named after the database, not directly in root.
fix
Update your code to expect backups in a subdirectory of the specified root, e.g., root/dbname.
affects: >=1.5.0
gotchaWhen using the 'stream' option to pipe .tar data, the stream must be a writable stream; otherwise the module may throw an error.
fix
Ensure you pass a proper writable stream, e.g., fs.createWriteStream('backup.tar').
affects: all
deprecatedNode engine requirement is >=4, which means it may not work on very old Node.js versions; consider updating to current LTS.
fix
Upgrade Node.js to version >=4.
affects: <4.0.0
Errors
Common errors & fixes
Error: Collection 'users' doesn't exist
The specified collection does not exist in the database.
fix
List collections in your database and correct the 'collections' option.
TypeError: backup is not a function
Incorrect import: using ES module import syntax or destructured required.
fix
Use 'const backup = require('mongodb-backup');'
Error: required 'root' option missing
The 'root' option is not provided in the options object.
fix
Add a 'root' property specifying the directory path for the backup.
Upgrade
Version history
1.6.9latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
21 hits · last 30 days
node
20
Resources
mongodb-backup — npm install mongodb-backup · libregistry