mongoose-seed-db
mongoose-seed-db lets you populate and clear MongoDB collections with all the benefits of Mongooses model validation
Basic example
var MongooseSeed = ;//import MongooseSeed from 'mongoose-seed-db'; //ES6 MongooseSeed;
Mongoose Model example
var mongoose = ;//import mongoose from 'mongoose'; //ES6 var test = name: type: String ; ;
Data example (.js)
moduleexports = model: 'Test' data: name: 'js-example-entry-1' name: 'js-example-entry-1' ;
Data example (.json)
Functions
MongooseSeed.connect(db)
Initializes connection to MongoDB via Mongoose.
MongooseSeed.loadModels(path)
Loads mongoose models from path, use: __dirname + '/path_to_models'
MongooseSeed.populate(path, options)
Populate MongoDB with data in js/json files from path, use: __dirname + '/path_to_data'
Options:
populateExisting: true/false
- defaults to true
- false = only populate models without existing documents
MongooseSeed.clearAll()
Clears all data from loaded models
MongooseSeed.clearModels(array)
Clears all data from list of models provided in array