Meteor Server

Meteor Server

December 16, 2009


Let’s begin defining the only server-side piece of our app (although it is also client-side in order to achieve latency compensation).

In the top-level directory of your app, create a collections.js file.

Now that we have the file, we need to add some logic. We want to define our collection (Hours) and two methods which will be called in our components.

Add the following outline to the collections.js file:

   Hours = new Meteor.Collection("Hours");



This creates a Meteor Collection which maps to the database. The empty Meteor methods object should get some functions now.

Add one method that inserts the hours and another that removes them. Name them insertHour and removeHour respectively. insertHour takes the number of hours and the date, checks for inconsistencies and saves into the DB. It makes use of the Meteor methods check and insert.

On the other hand, removeHour takes an id and removes an entry from the database.

Here is a suggestion for what it should be doing line by line. The full code can be found at the end of the tutorial.

     //Function insertHour takes 2 parameters, the number of hours and the date
     insertHour: function() {
       //Parse the first parameter to make sure it is an int
       CODE HERE
       //Use the check function to ensure that the first parameter is a number
       CODE HERE
       //Use the check function to ensure that the second parameter is a date
       CODE HERE
       //Return the insert function (add a key value pair (JSON) consisting of the first and second parameter into the Hours collection)
       CODE HERE

     // Function removeHour takes 1 parameter, the id to remove an entry
     removeHour: function() {    
       //Use the check function to ensure the parameter is a string
       CODE HERE
       //Return the remove function (remove an entry from the Hours collection by id)
       CODE HERE

Now that we have our server side code written, let's move on to our frontend code.


If you have feedback on this tutorial or find any mistakes, please open issues on the GitHub Repository.

Join Make School Icon

Join Make School

Prepare for your career as a founder or software developer

Apply now
Talk to Us Icon

Talk to Us

If you have any questions, please send us an email.

Email Us