Thanks to visit codestin.com
Credit goes to github.com

Skip to content

yiooxir/mongo-restore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •