# @dotmind/node-mongo-dump

> An npm package to generate database dump with customizable node cron

Latest version **1.1.0** (published 2022-03-28) · ISC license · 0 weekly downloads

## Install

```sh
npm install @dotmind/node-mongo-dump
pnpm add @dotmind/node-mongo-dump
yarn add @dotmind/node-mongo-dump
bun add @dotmind/node-mongo-dump
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2022-03-28 |
| First published | 2020-12-03 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 8 |
| Unpacked size | 13.4 KB |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| Author | Vincent |
| Maintainers | matthieuchane, mpetronio, esoulie1, bltnico, vincent.mind |
| Keywords | node, mongo, dump |

## Links

- npm: https://www.npmjs.com/package/@dotmind/node-mongo-dump
- Repository: https://github.com/dotmind/node-mongo-dump
- Homepage: https://github.com/dotmind/node-mongo-dump#readme
- Issues: https://github.com/dotmind/node-mongo-dump/issues
- npm.io page: https://npm.io/package/@dotmind/node-mongo-dump

## Dependencies (8)

- [semver](https://npm.io/package/semver.md) ^5.7.1
- [node-cron](https://npm.io/package/node-cron.md) 2.0.3
- [tz-offset](https://npm.io/package/tz-offset.md) 0.0.1
- [compressing](https://npm.io/package/compressing.md) 1.5.1
- [child_process](https://npm.io/package/child_process.md) 1.0.2
- [node-bin-setup](https://npm.io/package/node-bin-setup.md) 1.0.6
- [@types/node-cron](https://npm.io/package/@types/node-cron.md) 2.0.3
- [opencollective-postinstall](https://npm.io/package/opencollective-postinstall.md) 2.0.3

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 1.1.0 (latest) — 2022-03-28
- 1.0.5 — 2021-09-21
- 1.0.4 — 2021-09-21
- 1.0.3 — 2021-09-20
- 1.0.2 — 2021-02-10
- 1.0.1 — 2020-12-09
- 1.0.0 — 2020-12-03

## README

# node-mongo-dump

## Menu
  * [💻 Installation](#installation)
  * [🔨 Usage](#usage)
  * [📖 Options](#options)
  * [📜 License](#license)

Backup your MongoDB database on a specific frequency using mongodump.

[![Version](https://img.shields.io/npm/v/@dotmind/node-mongo-dump?color=brightgreen)](https://www.npmjs.com/package/@dotmind/node-mongo-dump)

## 💻 Installation

`npm i @dotmind/node-mongo-dump --save`

## 🔨 Usage

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 🚀

## 📖 Options


| 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.                                                                          |
| 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. |
| host       | false     | string  | `'localhost'`      | Your mongodb host.                                                                                                 |
| port       | false     | string  | `'27017'`          | Your mongodb port.                                                                                                 |
| outPath    | false     | string  | `'./../../dumps/'` | The directory where you want to save the dumps.                                                                    |
| withStdout | false     | boolean | `false`            | Variable to log the output of mongodump command                                                                    |
| withStderr | false     | boolean | `false`            | Variable to log the errors of mongodump command                                                                    |
| withClose  | false     | boolean | `false`            | Variable to log the ouendtput of mongodump command                                                                 |

### dumpDb

| 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. |
| host       | false     | string  | `'localhost'`      | Your mongodb host.                                                                                                 |
| port       | false     | string  | `'27017'`          | Your mongodb port.                                                                                                 |
| outPath    | false     | string  | `'./../../dumps/'` | The directory where you want to save the dumps.                                                                    |
| withStdout | false     | boolean | `false`            | Variable to log the output of mongodump command                                                                    |
| withStderr | false     | boolean | `false`            | Variable to log the errors of mongodump command                                                                    |
| withClose  | false     | boolean | `false`            | Variable to log the ouendtput of mongodump command              

Return the path where the file is saved.

## 📜 License
[ISC](https://choosealicense.com/licenses/isc/)

---
_Source: https://npm.io/package/@dotmind/node-mongo-dump · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
