Product College starts on September 5. Submit your application today. Apply now.

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.

Summer academy

An iOS Development Summer Course

Design, code and launch your own app. Locations across the USA and Asia

Find your location

Product College

A computer science college

Graduate into a successful career as a founder or software engineer.

Learn more