I just want to check because I don't see it in the docs. Maybe I'm just missing it.
As far as I can tell if I subscribe with skip then I don't skip on the client. Correct?
I'm using iron router. I have code like this
Router.route('/docs/:_page', {
template: 'doclist',
subscriptions: function() {
var page = parseInt(this.params._page) - 1;
var skip = page * 10;
var limit = 10;
return Meteor.subscribe("pages", skip, limit);
},
});
The corresponding publish is this
Meteor.publish("pages", function (skip, limit) {
return Docs.find({}, {skip: skip, limit: limit});
});
But now in the template helper I don't use the skip AFAICT because there's only limit
results in the MiniMongo
Template.doclist.helpers({
docs: function () {
var route = Router.current();
var pageId = parseInt(route.params._page) || 1;
var page = pageId - 1;
var skip = page * 10;
return Docs.find({}, {
// skip: skip
limit: limit,
});
},
});
It seems to work. If I comment in the skip
line then I get no results on page 2.
Is that correct or am I doing something wrong?
You are correct - the client does not require a skip
in this case. Let's say you have 100 documents in the DB and you skip the first 20 with a limit of 10. Then only 10 documents will exist on the client. Whenever you find
on the client (in your templates), you are querying the local database (in this case 10 documents), so a skip would be inappropriate.
I'll caution that all of this is predicated on the notion that you have only one subscription for Docs
. To extend the example above, if you had another 15 documents in the same collection on the client from another subscription, then you may need to do some additional filtering in order to show only the ones you are are interested in.