Last active
April 29, 2016 20:13
-
-
Save josephdburdick/62c776f163676406529b to your computer and use it in GitHub Desktop.
Seeds Mongo database but is immediately removed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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