Skip to content

Instantly share code, notes, and snippets.

@josephdburdick
Last active April 29, 2016 20:13
Show Gist options
  • Save josephdburdick/62c776f163676406529b to your computer and use it in GitHub Desktop.
Save josephdburdick/62c776f163676406529b to your computer and use it in GitHub Desktop.
Seeds Mongo database but is immediately removed.
Networks = new Mongo.Collection('networks');
Networks.remove({});
if (Meteor.isServer) {
Networks.allow({
insert: function (userId, doc) {
return true; //userId === doc.userId;
},
update: function (userId, doc, fieldNames, modifier) {
return true; // userId === doc.userId;
},
remove: function (userId, doc) {
return true; // userId === doc.userId;
}
});
}
if (Networks.find().count() === 0){
console.log("No networks. Seeding database...");
var network = function(){
return {
name: Fake.word() + "'s Network",
address: Fake.word() + ' ' +
Fake.fromArray(['Street', 'Road', 'Lane', 'Way', 'Avenue']),
createdAt: new Date().toDateString()
};
};
_(20).times(function(){
// Seed fake networks.
console.log('network: ', network());
// Meteor.call('insertNetwork', network());
Networks.insert(network());
});
console.log(Networks.find().count() + ' networks');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment