Seed data

I'm a fan of always being able to reset your data and rebuild from scratch. I see my app as a kind of balloon, with it looking different based on how much air (data) is in it. From this it makes sense that we should be able to easily change how much air is inside of it, and let it all out if need be.

You can reset your data at any time with meteor reset. And we can add some seed data so our app is not empty when we reset it. Basically every time our server starts up we want to check if our data is empty, and if it is we want to fill it up a bit with our seed data. We can do this with the following file:

server/seeds.js

Meteor.startup(function () {
  if (Teams.find().count() === 0) {
    [
      {name: "Barcelona"},
      {name: "Real Madrid"},
      {name: "Matt's team"}
    ].forEach(function(team){
      Teams.insert(team);
    });
  }
});

Note that Meteor.startup takes a function as a parameter that is run every time the server process is finished starting (docs).

Now we can reset all the data and start afresh.

meteor reset
meteor

Our seeded data