Does subscribing to a large collection pass all the data to the client?


#1

Hi, I have a search function and currently what I’m doing is, subscribe to my collection each time the search parameters change like this :

 Meteor.subscribe('job_search', searchParams).ready();

My question is, do we really have to do this? When fetching the data I use the search params. Will subscribing to all the data at once load all the data and reduce the performance of the app?


#2

Your subscription will get all data that your publish function exposes.

Note that you have not used the .ready() method as it’s intended to be used. I don’t think it will be working as I suspect you intended.


#3

Oh I see. Actually I’m taking the ready to a constant and loading the component only when it’s ready. I use this inside a container (Use react-komposer).

So do you think fetching the data through a method be a better solution?


#4

Not necessarily. A method gets you a snapshot of your collection based on the query you make at that time. If that’s OK for your use case, go with it. On the other hand, a subscription gives you reactive changes to your collection over time. Only you can apply your understanding of your use case to decide the best way to get your data.


#5

The general rule is: publish as much of your collection that you’ll need in your client for the duration of a particular page view. While in that view you would perform find() locally to display subsets of that data as required.

However, if the scope of data that could be required by a page is very large (unusual) and your local find() is both very selective and infrequent the balance shifts towards making a subscription request each time and using a local non-selective find(). As @robfallows says, you have to make a judgement call on your use case. Subscriptions are relatively heavy-weight (and often require a wait indicator).

Finally, the title of your post suggest a slight misunderstanding. It’s not the size of the collection in MongoDB that is the issue, it is the number of documents that you decide to publish from your collection (but maybe you meant that).