createdAt: -1 not showing newest tasks at the top


#1

Hello everyone!
I am new to Meteor and I am following the oficial tutorial.
In section 4- Forms and events, step 4.3 - Show newest tasks at the top , we have to add the following line but my task list is not showing the newest at the top as it was supposed to work. It is still being added as the last item on the list.

I appreciate your help on what I am doing wrong.

Thank you very much

Tutorial instructions:

// Show newest tasks at the top
return Tasks.find({}, {sort: {createdAt: -1}});

Here is my own code.

Tasks = new Mongo.Collection("tasks");

if (Meteor.isClient) {
  // This code only runs on the client
  Template.body.helpers({
    tasks: function () {
      // show newest tasks at the top
        return Tasks.find({}, {sort: {createdAt: -1}});
    }
  });


  Template.body.events({
    "submit .new-task": function (event) {

      //Prevent default browser form submit
      event.preventDefault();

      // Get the value from form element
      var text = event.target.text.value;

      // Insert a task into the collection
      Tasks.insert({
        text: text,
        createAt: new Date()//current time
      });

      //Clear form
      event.target.text.value = "";
    }
  });

    Template.task.events({
        "click .toggle-checked":function(){
            // Set the checked property to the opposite of its current value
            Tasks.update(this._id, {
                $set: {checked: ! this.checked}
            });
        },

        "click .delete": function(){
            Tasks.remove(this._id);
        }
    });

}

#2

you need to have that createdAt field in document
and it has to be in Date format


#3

Seems that’s accounted for @shock ?


#4

i see createAt there, not createdAt


#5

Ah my mistake - missed the typo! Is that the issue @natalisilverio ?


#6

Yes! You are right. Thank you very much you all