Meteor User Seed
I 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.
1if (Meteor.users.find().count() === 0) {
2 seed1UserId = Accounts.createUser({
3 username: 'lance',
4 email: '[email protected]',
5 password: '123456'
6 });
7 seed2UserId = Accounts.createUser({
8 username: 'david',
9 email: '[email protected]',
10 password: '123456'
11 });
12 seed3UserId = Accounts.createUser({
13 username: 'glenn',
14 email: '[email protected]',
15 password: '123456'
16 });
17 seed4UserId = Accounts.createUser({
18 username: 'martin',
19 email: '[email protected]',
20 password: '123456'
21 });
22}
23
24if (MasterList.find().count() === 0) {
25
26 MasterList.insert({
27 firstname: "Lance",
28 lastname: "James",
29 user\_id: seed1UserId
30 });
31
32 MasterList.insert({
33 firstname: "David",
34 lastname: "Cope"
35 user\_id: seed2UserId
36 });
37
38 MasterList.insert({
39 firstname: "Glenn",
40 lastname: "Manner",
41 user\_id: seed3UserId
42 });
43
44 MasterList.insert({
45 firstname: "Martin",
46 lastname: "Drone",
47 user\_id: seed4UserId
48 });
49}