I am probably missing something quite obvious or missing something in the documentation. I searched and did not find similar question. posting it.
Both of these
return Items.find({},{sort: {time: -1}, limit: 10});
or
return Items.find({},{sort: {time: -1}).limit(10);
result in meteor cannot observe queries with skip or limit
UPDATE: This is longer an issue. Beginning with Meteor 0.5.3, you can observe queries with skip
and limit
options.
Unfortunately, this is true: the mimimongo package doesn't currently support calling observe
on cursors that used the skip
or limit
options. There's no good reason for this; it's just not implemented.
If you're calling this query inside a template helper, there's an easy workaround:
Template.name.items = function () {
// fetch array of all the items
var items = Items.find({}, {sort: {time: -1}}).fetch();
// return only the first 10 items to the template
return items.slice(0,10);
};
The downside of the workaround is efficiency. If your helper returns a cursor (just returning the value of Items.find
without calling fetch
, then the template system is smart enough not to recalculate the whole template when just one item changes, or if a new item is inserted.
On the other hand, calling fetch
in the helper registers a dependency on the entire query result, so the whole template gets recalculated any time any object in the query changes.
There's no other difference. The template will put the same thing on the screen and it will preserve the contents of form elements when it has to redraw itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With