Populate MongoDB with dummy collections for testing
mongo-fixtures will read JSON documents from disk, and use them to quickly populate a MongoDB database. You can use it to bootstrap a local environment, or to initialise data required for functional tests.
The fake data is organised in "datasets", which represent a whole set of consistent data. They are just folders on disk, containing both files and folders:
dataset1|___ users.coffee|___ history.coffee|___ products|___ phone.coffee|___ guitar.coffee
Maybe a personal preference, but it:
# valid user without an address_id: ObjectID'fffffffffffffff000000001'name: 'John Doe'memberSince: '28 Mar 2013'
The config file has 2 main sections.
examples folder for an config file you can copy).
datasets:bootstrap: "/dataset1"functests: "/dataset2"
envs:local:: 'mongodb://localhost:27017/mystore'collections: 'users''products''history'dev:: "mongodb://:@alex.mongohq.com:10023/mystore"collections: 'products'
npm install mongo-fixtures!
Great for build scripts
fixtures = require 'mongo-fixtures'options =dataset: 'bootstrap'env: 'local'username: nullpassword: nullfixturesconfigload optionsfinish
Will prompt you for all required values
fixtures = require 'mongo-fixtures'fixturesconfiginteractive finish
A sample callback would be:
=if errconsolelog errprocessexit 1elseconsolelog resprocessexit 0