mongo-database-backup
v1.2.0
Published
[![NPM version](https://img.shields.io/npm/v/mongo-database-backup.svg)](https://www.npmjs.com/package/mongo-database-backup)
Downloads
10
Readme
mongo-database-backup
Backup for mongodb
Look at mongo-database-backup-cli-tools
for command line usage, similar to mongodump
Installation
Install through NPM
npm install mongo-database-backup
API
inside nodejs project - Backup Database in .gzip file
const {backupDB, restoreDb, backupCollection, restoreCollection} = require('mongo-database-backup');
const db = 'databaseName';
const uri = `mongodb://0.0.0.0:27017/${db}`;
backupDB(db, uri).then(result => console.log(result)).catch(err => console.log(err))
inside nodejs project - Restore Database function
const db = 'databaseName';
const uri = `mongodb://0.0.0.0:27017/${db}`;
const root = `./backup/${db}.gzip`;
restoreDb(db, uri, root).then(result => console.log(result)).catch(err=> console.log(err));
inside nodejs project - Backup Collection in MongoDB database .bson file
const db = 'databaseName';
const dbCollection = 'collectionName';
const uri = "mongodb://0.0.0.0:27017/";
backupCollection(db, uri, dbCollection).then(result => console.log(result)).catch(err=> console.log(err));
inside nodejs project - Restore Collection in MongoDB database
const db = 'databaseName';
const dbCollection = 'collectionName';
const uri = "mongodb://0.0.0.0:27017/";
const root = `./backup/${dbCollection}.bson`;
restoreCollection(db, uri, dbCollection, root).then(result => console.log(result)).catch(err=> console.log(err));
backup(options)
options
Examples
Take a look at my [examples]