Weird Behiviour of findOne


#1

Hi guys,

Let’s assume I have a collection called Books
{ title : “string”,
author : “string”}

Let’s take a look on following code

Template.bookList.helpers({ books: function() { console.log('meteor'); return Posts.find(); } }); In this case the 'meteor' will be printed one time. But if i use findOne like this Template.bookItem.helpers({ book: function() { console.log('meteor'); return Posts.findOne({'title':'title of the book'}); } }); The 'meteor' will be printed several times(in some case two in some six).

Why’s that !?


#2

In the first case, you returned a cursor. Then blaze know how to render it in efficient manner.

In the second case you return a JS object to blaze. And that helper is re-run for every change in that document. (That’s does by findOne)

That’s the difference.