Weird Behiviour of findOne

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 !?

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.

3 Likes