-
Notifications
You must be signed in to change notification settings - Fork 73
Open
Labels
Description
Either with an env variable and JSON seed file (more flexible, can touch multiple collections), or a more simple one collection check. Example for a package called packageName, this code will run a seed function only if the collection does not exist
// Seed the database...
mongoose.connection.db.listCollections({
name: 'packageName'
})
.next(function(err, collinfo) {
if (!collinfo) {
console.log('packageName collection does not exist, seeding!');
var defaultData = require('./server/models/packageName.seed');
var Model = mongoose.model('packageName');
Model.insertMany(defaultData, function(err, r) {
if (err) {
console.log(err);
}
if (r) {
console.log(r);
}
});
}
});
packageName.seed
module.exports = [{
foo: bar,
baz: fuzz
}];
Reactions are currently unavailable