mchance

0.1.3 • Public • Published

mchance

mongoose + chance = this thing

Example

// of course first make sure to `npm install mongoose mchance`
 
var mongoose = require('mongoose');
var db = mongoose.connect('mongodb://localhost:27017/insert-db-name-here').connection;
var mchance = require('mchance')(db);
 
db.model('User', new mongoose.Schema({
  email: {
    type: String,
    seed: mchance.email
  }
}));
 
db.model('Comment', new mongoose.Schema({
  user: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'User'
  },
  text: {
    type: String,
    seed: mchance.paragraph
  }
}));
 
db.seed({
  User: 1,    // generate 1 user
  Comment: 2  // generate 2 comments
})
.then(function (dbCache) {
  // dbCache contains ref names and *saved* documents
  console.log('---seeded users---');
  console.log(dbCache.User);
  console.log('---seeded comments---');
  console.log(dbCache.Comment);
});

Readme

Keywords

none

Package Sidebar

Install

npm i mchance

Weekly Downloads

2

Version

0.1.3

License

ISC

Last publish

Collaborators

  • hippiccolo