Is it possible to manually clean minimongo(client) only collection?

I have been playing with NO_MERGE_NO_HISTORY publication strategy and I think it could be a nice optimization. However I am not sure how would I cleanup minimongo collection after I move to another template and resubscribe with different params. Without manual client control this is basically a memory leak.
Right now I have pagination (e.g. each increment sends 10 docs). With MERGE new increment will remove previous 10 and I would prefer to simply keep adding up. Once moved from template simply clean everything and start over with new params.

OK now I do like this and seems to be working:

Template.template.onDestroyed(function() {
    myCollection._collection.remove({'channel': currentChannel});
});

I seems to be working and now I can use very light NO_MERGE_NO_HISTORY strategy. Basically before I had normal meteor infinity scroll where I increase number for elements to be loaded. It was working well but with NO_MERGE_NO_HISTORY I can select only next page of elements instead of ever increasing number. This approach allows to avoid increasing load on mongo and allows to skip expensive merge altogether with basically same result.

So you see any problems with using such pattern for infinity scroll?

2 Likes