# mongo-collections-dumper

> Easily dump and restore small mongo collections without using mongodump. Useful for fixtures reloading.

Latest version **1.0.7** (published 2017-02-09) · 0 weekly downloads

## Install

```sh
npm install mongo-collections-dumper
pnpm add mongo-collections-dumper
yarn add mongo-collections-dumper
bun add mongo-collections-dumper
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.7 |
| Published | 2017-02-09 |
| First published | 2016-12-13 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | nieziemski |

## Links

- npm: https://www.npmjs.com/package/mongo-collections-dumper
- npm.io page: https://npm.io/package/mongo-collections-dumper

## Dependencies (1)

- [ejson](https://npm.io/package/ejson.md) ^2.1.2

## Recent versions

- 1.0.7 (latest) — 2017-02-09
- 1.0.5 — 2016-12-15
- 1.0.4 — 2016-12-13
- 1.0.3 — 2016-12-13
- 1.0.2 — 2016-12-13
- 1.0.1 — 2016-12-13
- 1.0.0 — 2016-12-13

## README

# Mongo collections dumper
This is lightweight utility that allows you to easily dump and restore mongo collections. No mongodump dependency. Data can be stored in memory or on disk. Useful for fixtures reload.

# Usage
## With memory storage
```javascript
import MongoDumper from 'mongo-collections-dumper';

let db = ...; // get database handler;

runSomeFixtures(); // prepare some data to dump

// save all collections in array
let fixturesData = MongoDumper.dump({
    storage: 'memory',
    db
});


// tests are great use case for mongo dumper
describe('Users', () => {
    beforeEach(function () {
        // rollback database to starting point before each test
        MongoDumper.restore({
            storage: 'memory',
            collectionsData: fixturesData,
            db
        });
    });
});

```

## With file storage
```javascript
import MongoDumper from 'mongo-collections-dumper';

let db = ...; // get database handler;

// fixtures for empty project are great use case for mongo dumper
if (databaseIsEmpty()) {

    // you can setup database from file added to project repo
    let {restored} = MongoDumper.restore({
        storage: 'file',
        file: 'fixtures.json',
        db
    });

    // if there's no file you can add fixtures and add them to repo
    if (!restored) {
        runSomeFixtures();

        MongoDumper.dump({
            storage: 'file',
            file: 'fixtures.json',
            db
        });        
    }

}
```

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