# node-populator-mongodb

> A simple library used to populate a MongoDB database with native driver. Usefull for unit tests.

Latest version **0.0.3** (published 2016-01-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install node-populator-mongodb
pnpm add node-populator-mongodb
yarn add node-populator-mongodb
bun add node-populator-mongodb
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2016-01-08 |
| First published | 2016-01-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Known vulnerabilities | 0 (+2 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | 9 Février |
| Maintainers | 9fevrier |
| Keywords | node, mongodb, populator, populate, unit tests, data |

## Links

- npm: https://www.npmjs.com/package/node-populator-mongodb
- Repository: https://github.com/9fevrier/node-populator-mongodb
- Issues: https://github.com/9fevrier/node-populator-mongodb/issues
- npm.io page: https://npm.io/package/node-populator-mongodb

## Dependencies (5)

- [bunyan](https://npm.io/package/bunyan.md) ^1.5.1
- [mongodb](https://npm.io/package/mongodb.md) ^2.1.3
- [kerberos](https://npm.io/package/kerberos.md) 0.0.17
- [es6-promisify-all](https://npm.io/package/es6-promisify-all.md) ^0.1.0
- [pigalle-promises-control-flow](https://npm.io/package/pigalle-promises-control-flow.md) ^0.0.2

## 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

- 0.0.3 (latest) — 2016-01-08
- 0.0.2 — 2016-01-07
- 0.0.1 — 2016-01-07

## README

Node Populator for MongoDB
==========================

A simple library used to populate a MongoDB database with native driver. Usefull for unit tests.

## How to install ?

```
npm install node-populator-mongodb
```

## Example usage

### Create testing data

```javascript
'use strict;';

var ObjectID = require('mongodb').ObjectID;
var DBRef = require('mongodb').DBRef;

var getDBRef = function(collectionName, id) {
    return new DBRef(collectionName, id, 'populator_test');
};

module.exports = [
        {
            _id: new ObjectID("200000000000000000000001"), 
            name: "Project 1", 
            customer: getDBRef("customer", "300000000000000000000001") 
        },
        {
            _id: new ObjectID("200000000000000000000002"), 
            name: "Project 2", 
            customer: getDBRef("customer", "300000000000000000000002") 
        }
    ];
```

```javascript
'use strict;';

var ObjectID = require('mongodb').ObjectID;
var DBRef = require('mongodb').DBRef;

var getDBRef = function(collectionName, id) {
    return new DBRef(collectionName, id, 'populator_test');
};

module.exports = [
        {_id: new ObjectID("300000000000000000000001"), name: "Customer 1" },
        {_id: new ObjectID("300000000000000000000002"), name: "Customer 2" }
    ];
```

* Each exported key (as `customer`, `project`) is corresponding to a MongoDB collection. 
* In each collection, you must define an array containing wished records.

### Create unit test

* We'll use [mocha](http://visionmedia.github.io/mocha/ "Mocha test framework") to run unit tests.

```javascript
'use strict;';

var data = require('testing-data'),
    PopulatorMongoDB = require('node-populator-mongodb'),
    CustomerService = require('customer-service');

var customerService = new CustomerService();

var dbUri = 'mongodb://localhost:27017/populator_test';

/**
 * Unit tests to validate GenericDaoMongoose.
 */
describe('Customers test', function () {

    /**
     * Before each test, drop the collection then populate.
     */
    beforeEach(function (done) {
        this.timeout(3000);
        var populator = new PopulatorMongoDB(dbUri, data);
        populator.populate(done);
    });

    /**
     * Create new object(s).
     */
    describe('create', function () {
        it('create a new customer', function (done) {
            customerService.create({name: 'customer test new 1'}, function (err, result) {
                    assert.equal(err, null);
                    assert.equal(result.name, 'customer test new 1');
                    done(err);
                }
            );
        });
	});
});
```

### Run your tests

```
mocha
```

### Example in real life

    `todo`


## Change history

* **v0.0.2** :
  * Fix bug: invalid path of resources.
* **v0.0.1** :
  * Initial version

## License

    The MIT License (MIT)
    
    Copyright (c) 2016, 9 Février <contact@9fevrier.com>
    
    Permission is hereby granted, free of charge, to any person obtaining a copy of
    this software and associated documentation files (the "Software"), to deal in
    the Software without restriction, including without limitation the rights to
    use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
    the Software, and to permit persons to whom the Software is furnished to do so,
    subject to the following conditions:
    
    The above copyright notice and this permission notice shall be included in all
    copies or substantial portions of the Software.
    
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
    FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
    COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
    IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
    CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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