An npm package to generate database dump with customizable node cron
npm install @dotmind/node-mongo-dumpBackup your MongoDB database on a specific frequency using mongodump.

npm i @dotmind/node-mongo-dump --save
Declare the function in the js file that start your server
``javascript
const nodeMongoDump = require('@dotmind/node-mongo-dump');
nodeMongoDump({
dbName: 'YOUR_DB_NAME'
});
`
You can use the dumpDb function to dump the database once
`javascript
const dumpDb = require('@dotmind/node-mongo-dump/lib/dumpDb');
dumpDb({
dbName: 'dbName',
host: 'localhost',
port: '27017',
nbSaved: 5,
outPath: './dumps/',
withStdout: false,
withStderr: false,
withClose: false,
});
`
And you can use await for a sync usage. The dumpDb function will return the path where the file is saved.
`javascript`
const file = await dumpDb({
dbName: 'dbName',
host: 'localhost',
port: '27017',
nbSaved: 5,
outPath: './dumps/',
withStdout: false,
withStderr: false,
withClose: false,
});
And then... That's it, you're ready to go 🚀
| Arguments | Required | type | Default Value | Commentary |
| ---------- | --------- | ------- | ------------------ | ------------------------------------------------------------------------------------------------------------------ |
| dbName* | true | string | | Your database name |
| frequency | false | string | '0 0 *' | How often you want to dump your database. |14
| nbSaved | false | number | | The number of dumps you want to keep. If you reach the nbSaved, it will delete the oldest before saving a new one. |'localhost'
| host | false | string | | Your mongodb host. |'27017'
| port | false | string | | Your mongodb port. |'./../../dumps/'
| outPath | false | string | | The directory where you want to save the dumps. |false
| withStdout | false | boolean | | Variable to log the output of mongodump command |false
| withStderr | false | boolean | | Variable to log the errors of mongodump command |false
| withClose | false | boolean | | Variable to log the ouendtput of mongodump command |
| Arguments | Required | type | Default Value | Commentary |
| ---------- | --------- | ------- | ------------------ | ------------------------------------------------------------------------------------------------------------------ |
| dbName* | true | string | | Your database name |
| nbSaved | false | number | 14 | The number of dumps you want to keep. If you reach the nbSaved, it will delete the oldest before saving a new one. |'localhost'
| host | false | string | | Your mongodb host. |'27017'
| port | false | string | | Your mongodb port. |'./../../dumps/'
| outPath | false | string | | The directory where you want to save the dumps. |false
| withStdout | false | boolean | | Variable to log the output of mongodump command |false
| withStderr | false | boolean | | Variable to log the errors of mongodump command |false` | Variable to log the ouendtput of mongodump command
| withClose | false | boolean |
Return the path where the file is saved.