Different subscriptions for a same collection

#1

I have 2 sections in a page, one that lists documents (clickable menu that selects a document), and one that displays the document selected.
Documents are big, so I would like to achieve the following:

  • A subscription to a “page” of documents (skip, limit) with only the document name in fields

  • The possibility to display the whole selected document

How to use the subscriptions to achieve that?

#2

That should work like this.

On the server:

Meteor.publish('articles-intros', function({ skip, limit }) {
  return ArticlesCollection.find({}, {
    fields: { name: 1 },
    sort: { createdAt; -1 },
    skip,
    limit,
  });
});
// Keep in mind, no validations yet so insecure 
Meteor.publish('article-details', (articleId) => {
  return ArticlesCollection.find(articleId);
});

On the client:

Meteor.subscribe('article-intros', { skip: 0, limit: 10 });

Meteor.subscribe('article-details', articleId);
2 Likes
#3

Thanks, perfect answer