Registry / database / mongodb-backup-toolkit

mongodb-backup-toolkit

JSON →
library1.0.8jsnpmunverified

A Node.js library (v1.0.8) for backing up and restoring MongoDB databases using Mongoose. It exports all collections as JSON files to a specified directory and restores them by reading and inserting those files. Different from mongodump/restore by being a pure-JS solution with no CLI dependency. Intermittent updates with basic functionality; not actively maintained.

npm install mongodb-backup-toolkit
INSTALL
IMPORT
SIG · MONGODB-BACKUP-TOO
M
mongodb-backup-toolkit
databasejavascriptv1.0.8
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 export
import MongoBackupToolkit from 'mongodb-backup-toolkit'
const MongoBackupToolkit = require('mongodb-backup-toolkit')
Package is ESM-only. Use the default import.
named imports (backup/restore)
import { backup, restore } from 'mongodb-backup-toolkit'
const { backup, restore } = require('mongodb-backup-toolkit')
Named exports are available since v1.0.0. CommonJS require will fail.
type imports (TypeScript)
import type { MongoBackupToolkit } from 'mongodb-backup-toolkit'
import { MongoBackupToolkit as type } from 'mongodb-backup-toolkit'
TypeScript types are bundled. Use import type for type-only usage.

Demonstrates ESM import, backup and restore using default export, with environment variable for URI.

import MongoBackupToolkit from 'mongodb-backup-toolkit'; // Backup all collections from the database to './backup' directory const uri = process.env.MONGO_URI ?? 'mongodb://localhost:27017/mydatabase'; const backupPath = './backup'; await MongoBackupToolkit.backup(uri, backupPath); console.log('Backup completed.'); // Restore from the backup directory await MongoBackupToolkit.restore(uri, backupPath); console.log('Restore completed.');
Debug
Known issues
breakingThe restore function deletes all existing documents in target collections before inserting. Equivalent to --drop in mongorestore.
fix
Ensure the restore operation is intended to replace all data, or modify the source code to handle upsert instead.
affects: >=1.0.0
deprecatedOnly supports Mongoose 8.x and below. Not tested with newer Mongoose versions.
fix
Check compatiblity; may need to use older Mongoose or fork the package.
affects: <=1.0.8
gotchaBackup will fail if the MongoDB URI points to an atlas cluster without proper network whitelisting or authentication.
fix
Ensure the MongoDB URI has correct credentials and that the IP is whitelisted in Atlas.
affects: >=1.0.0
gotchaThe backup directory is created with default file permissions (umask) and may not be accessible if run as root.
fix
Run the backup with a dedicated user or manually set permissions after backup.
affects: >=1.0.0
gotchaEach collection is saved as a single JSON file. Large collections (>100MB) may cause memory issues if loaded entirely into RAM.
fix
Use mongodump for large databases or implement streaming in a custom script.
affects: >=1.0.0
Errors
Common errors & fixes
require() of ES Module not supported
Package is ESM-only; using CommonJS require() fails.
fix
Use import instead of require, or use dynamic import() in CJS context.
Error: backup(-/restore) is not a function
Using named import incorrectly on default export.
fix
Use default import: import MongoBackupToolkit from 'mongodb-backup-toolkit' then call MongoBackupToolkit.backup().
MongooseError: The `uri` parameter to `openUri()` must be a string
Passing undefined or non-string URI.
fix
Ensure the URI is provided as a string, e.g., const uri = process.env.MONGO_URI ?? 'mongodb://localhost:27017/mydatabase';
Error: ENOENT: no such file or directory, open './backup/collection.json'
Backup directory or file does not exist or wrong path during restore.
fix
Verify the backup path and that the files exist. Use an absolute path or ensure the directory is correctly created.
Upgrade
Version history
1.0.8latest on npm
Audit
Dependencies
mongooserequiredProvides MongoDB connection and data modeling for backup/restore operations
Agent activity
10 hits · last 30 days
node
10
Resources
mongodb-backup-toolkit — npm install mongodb-backup-toolkit · libregistry