Meteor: Single Document Subscription

Whenever I come across code snippets on the Internet, I see something like

Meteor.subscribe('posts', 'bob-smith');

The client can then display all the bob-smith messages.

A subscription returns multiple documents .

What I need, on the contrary, is a subscription to one document to show the body field of the article. I would like to filter by (article) id:

Meteor.subscribe('articles', articleId);

But I was suspicious when I searched the Internet for similar examples: I can not find a single example of subscribing to a single document.

What is the reason for this? Why doesn't anyone use single-document subscriptions?

+4
source share
2 answers

Oh, but people do!

, .

, github Telescope, .

, .

, . , /, :

Meteor.publish('singleArticle', function (articleId) {
  return Articles.find({_id: articleId});
});

// Then, from an iron-router route for example:
Meteor.subscribe('singleArticle', this.params.articleId);
+5

, , , : /posts/:_id - : .

+1

Source: https://habr.com/ru/post/1605746/


All Articles