1.0.8 • Published 3 years ago
mongodb-backup-toolkit v1.0.8
Mongodb Backup Toolkit
This Node.js library that allows you to easily backup and restore MongoDB databases using Mongoose and the filesystem module. The backup function writes all collections to individual JSON files in a specified directory, while the restore function reads the JSON files and inserts them into the specified database.
Installation
npm install mongodb-backup-toolkitor yarn
yarn add mongodb-backup-toolkitUsage
import MongoBackupToolkit from "mongodb-backup-toolkit";
// Backup
await MongoBackupToolkit.backup(
"mongodb://localhost:27017/mydatabase",
"backup"
);
// Restore
await MongoBackupToolkit.restore(
"mongodb://localhost:27017/mydatabase",
"backup"
);Pro Tip:
If you're using Nodemon to run your application, make sure to ignore the backup folder created by the BackupToolkit. You can add the backup folder to the nodemon ignore list in your nodemon.json or nodemon.config.js file:
{
"ignore": ["backup"]
}API
| Function | Description |
|---|---|
| backup | Backup a MongoDB database to a specified directory |
| restore | Restore a MongoDB database from a specified directory |