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 or comment below.

Summer academy

An iOS Development Summer Course

Design, code and launch your own app. Locations in San Francisco and Asia

Find your location

Product College

A computer science college

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

Learn more

Cookies on Make School's website

We have placed cookies on your device to ensure that we give you the best experience on our website.

This site uses cookies to deliver our services. By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Your use of Make School’s Products and Services is subject to these policies and terms.

Please note that Make School no longer supports Internet Explorer

We recommend upgrading to a modern web browser. Learn more