mongo-restore

0.1.3 • Public • Published

mongo-restore

Simple module for populate data to mongo collection from js/json

Useful things

It's very important to write code faster and not spend a lot of time for create and manage any fixture for checking if you code work well... This simple module get you simple and fast method for populating your mongo db collection on the fly.

Install

I sure, it is normal to use dev dependency for that:

npm install mongo-restore -D

Usage

Create some directory in you project. Place any files with data there. Run mongo-restore just tell him there is it have to looking for you fixtures and how you test base is called:

|-project
|--tests
|---fixtures
|----myTestCollection.js  //  (file inners: module.exports = {a: 1, b: 2})
|----myTestColl2.json     // You also can use json type
const restore = require('mongo-restore');
// using with promises
restore({path: '/tests/fixtures', dropDb: true})
  .then(res => console.log('test db restored'))
  .catch(err => console.error(err))

// using callback
restore({path: '/tests/fixtures', dropDb: true}, (err, res) => {
  if (err) console.error(err); return;
  console.log('test db restored')
})

This code remove all data from mongo test db and create two collections with same names as you fixture files are called (First one: myTextCollection; second one: myTextColl2)

Package Sidebar

Install

npm i mongo-restore

Weekly Downloads

24

Version

0.1.3

License

MIT

Last publish

Collaborators

  • yiooxir