O'Reilly logo

Meteor: Full-Stack Web Application Development by Marcelo Reyna, Isaac Strack, Fabian Vogelsteller

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding post examples

To query the database for posts, we need to add some post examples. This has to be done on the server, as we want to add them persistently. To add an example post, perform the following steps:

  1. We create a file called main.js inside our my-meteor-blog/server folder. Inside this file, we will use the Meteor.startup() function to execute the code on the start of the server.
  2. We then add the post example, but only when the collection is empty. So to prevent this, we add them every time we restart the server, as follows:
    Meteor.startup(function(){ console.log('Server started'); // #Storing Data -> Adding post examples if(Posts.find().count() === 0) { console.log('Adding dummy posts'); var dummyPosts = [ { title: 'My First entry', slug: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required