In Meteor, how can I query only the records of a given subscription?

前端 未结 3 1649
北海茫月
北海茫月 2020-12-18 07:09

I understand that a a subscription is a way to flow records into a client-side collection, from this post, and others...

However, per this post, You can have multipl

3条回答
  •  感情败类
    2020-12-18 08:00

    This is what's happening:

    Say that your server-side BlogPosts Mongo collection contains 500 posts from 10 different users. You then subscribe to two different subscriptions on the client:

    Meteor.subscribe('posts-current-user'); // say that this has 50 documents
    Meteor.subscribe('posts-by-user', someUser); // say that this has 100 documents
    

    Meteor will see Meteor.subscribe('posts-current-user'); and proceed to download the posts of the current user to the client-side Mini-Mongo's BlogPosts collection.

    Meteor will then see Meteor.subscribe('posts-by-user', someUser); and proceed to download the posts of someuser to the client-side Mini-Mongo's BlogPosts collection.

    So now the client-side Mini-Mongo BlogPosts collection has 150 documents, which is a subset of the 500 total documents in the server-side BlogPosts collection.

    So if you did BlogPosts.find().fetch().count in your client (Chrome Console) the result would be 150.

提交回复
热议问题