Meteor User Seed
I have been trying to build a site with Meteor and have slowly started getting stuff working.
Nov 10, 20141 min read
have been trying to build a site with Meteor and have slowly started getting stuff working.
One of the ways to populate your development data has been with database seeding.
I wanted to link a user account with a document in one of my collections so I worked this out from the documentation.
You add users to the users collection this returns the userId for the new user which you capture in a variable that you use to insert the userId into your second collection.
if (Meteor.users.find().count() === 0) {
seed1UserId = Accounts.createUser({
username: 'lance',
email: 'l@oo.com',
password: '123456'
});
seed2UserId = Accounts.createUser({
username: 'david',
email: 'd@oo.com',
password: '123456'
});
seed3UserId = Accounts.createUser({
username: 'glenn',
email: 'g@oo.com',
password: '123456'
});
seed4UserId = Accounts.createUser({
username: 'martin',
email: 'm@oo.com',
password: '123456'
});
}
if (MasterList.find().count() === 0) {
MasterList.insert({
firstname: "Lance",
lastname: "James",
user\_id: seed1UserId
});
MasterList.insert({
firstname: "David",
lastname: "Cope"
user\_id: seed2UserId
});
MasterList.insert({
firstname: "Glenn",
lastname: "Manner",
user\_id: seed3UserId
});
MasterList.insert({
firstname: "Martin",
lastname: "Drone",
user\_id: seed4UserId
});
}Did you enjoy this article?
Recommend it — Standard Reader surfaces well-loved writing to more readers across the network.