Override Previous Subscriptions


#1

Hi there. I am very new to Meteor, so it is entirely possible if not likely that I am missing something obvious, but I have not found the answer to this elsewhere.

I am running into a situation in my app where I have a very large collection (many documents and many fields in each document) so I am trying to only load the necessary data for each screen. Since I need the most recent document on every page, I am subscribing to this one document in my main layout component, which works well.

However, now I need the 10 most recent on a later screen (still a child of the above layout) and it seems to me that because I filtered it above, I cannot get more than the 1 I published and subscribed to in my layout, even though I am calling a new pub/sub with a new client-side query.

I know I can maybe call stop() on the sub in the layout, though since it is in the layout am not sure about that, however once I leave this page, I will need the original sub again. Ideally, I’d be able to subscribe to the dataset I need for this page which would override the previous one, and then when done, revert back to the previous subscription. However, I do not know if this is even possible since I cannot find this asked anywhere.

I am using React and React Router, if that helps. I have a layout component with the single document sub, and then this new component is a child of the layout one. If there is anything else I can provide to clear things up, let me know and I would be happy to do so. Thanks!


#2

I don’t think this answer will be useful for most people, but in case someone else sees this on a search, the answer here is that the collection merge does work the way I understood it where it takes all documents published and loads them on the client. My issue is I was filtering by one field that I wasn’t publishing, so no documents in my new publish ever matched. Adding the new field into the new publish allowed this work as expected.