Fetching data inside a templates' events code

I want to test a few things that regards some data i have stored stored in a collection called exams. This is my code

Template.Examinations.events({
					 'click .reactive-table tr': function() {
           Session.set('selectedPersonId', this._id); 
           var cursor = Exam.findOne(Session.get("selectedPersonId"));
           if (!cursor.count()) return;
            cursor.forEach(function(doc){
              console.log(doc._id);
            });	   
            //Uncaught TypeError: cursor.count is not a function
             },
});

Everytime i run the code by clicking a row,i get the error

//Uncaught TypeError: cursor.count is not a function

Why am i getting this error?.

You can use .count() on a .find() query, but not on a .findOne() query.

1 Like

Just to expand on @vigorwebsolutions answer: find returns a cursor, findOne returns an object (document).

1 Like