Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including mongo-loader with all npm packages installed. Try it out:

var mongoLoader = require("mongo-loader")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

mongo-loader v1.0.0

Loads data from json files into a database and can remove as well, useful for testing and seeding a database"

Mongo-Loader

Take json files and load them as collections into mongodb, then deletes them from the db when the tests are run.

Install

npm install mongo-loader --save-dev

Usage

var loader = require('mongo-loader');

loader.import(function () {
    //open a connection to your mongodb and data is there
});
//when done
loader.purge(function () {
   //additional clean up tasks 
});

The JSON Files

The files need to be in tests\fixtures and named one per collection. Check out the folders in this repo to see.

Configuring the connection

This module uses mongo-startand xtconf to connect so a config.json file with a "mongo-connection" in it will get you up and running.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free