Skip to content

HungryUp/mongoose-seed-plus

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mongoose-seed-plus

mongoose-seed-plus lets you populate and clear MongoDB documents with all the benefits of Mongoose validation

npm install mongoose-seed-plus --save-dev 

Basic example

// open => seed.js var seeder = require('mongoose-seed-plus'); // Connect to MongoDB via Mongoose seeder.connect('mongodb://localhost:27017/mongoose-seed-plus-dev', function() { // Start processing... seeder.start(__dirname + '/migrations', [ { path: 'models/Product.js', name: 'Product', clear: true }, { path: 'models/User.js', name: 'User', clear: true }, ], true); }); 

Data files

Create file .json in folder migrations.

Structure

├── seed.js └─┬ migrations ├── users.json ├── products.json 

Example

// open => migrations/users.json // Data object containing seed data - documents organized by Model { "model": "User", "documents": [ { "firstname": "Christopher", "lastname": "Fouquier", "email": "christopher.fouquier@gmail.com", "password": "root", "role": "admin" }, { "firstname": "John", "lastname": "Doe", "email": "john.doe@awesome.com", "password": "123" } ] }

Methods

seeder.connect(db, [callback])

Initializes connection to MongoDB via Mongoose singleton.

seeder.start(path, models, [dump])

seeder.start(__dirname + '/migrations', [ /**  * @path (string, required) : path to model  * @name (string, required) : name of model  * @clear (boolean, required) : clear DB collection  */ { path: 'models/User.js', name: 'User', clear: true }, { path: 'models/Product.js', name: 'Product', clear: false }, ], true);

About

Seed data population for Mongoose

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • JavaScript 100.0%