Separate two Subscripitons on one Collection


#1

I have a single page on which I have two subscriptions to the same ‘Records’ collection. These are for:

Search - a subscription that finds records based on a fairly complex filter. I only return headline data for this with most fields filtered out.
Active - a simple subscription by ID which checks user rights more stringently and triggers logging of all access to the actual record.

The problem is that unless I replicate the search result logic used in the publication on the client, I end up with both the currently searched records as well as the active record being shown in a simple list of all records in the collection.

The best solution I could think of was to use dburles:collection-helpers to create a single place for this search, but I actually would prefer to hide this logic from the client altogether.

Is there any way I can access just the records returned based on a specific subscription?


#2

That is the recommended solution. Meteor’s “merge box” always seeks to ensure that the client has the results of all active subscriptions available to the client.


#3

Subscriptions are basically just for bandwidth/memory management and security.

Also, if the collection isn’t too large, you could consider simply subscribing to the entire collection. Then it’s all preloaded and your search will be snappier (if you’re doing real-time search results).


#4

What I sometimes do to separate data from different (non-overlapping) subscriptions:

Meteor.publish('pubX', function (parms) {
  const cursor = Coll.find(parms);
  const observer = cursor.observe({
  added: (doc) => {
    doc._select = 'X'
    this.added(collName, doc._id, doc)
  }
...
}

Meteor.publish('pubY', function (parms) {
  const cursor = Coll.find(parms);
  const observer = cursor.observe({
  added: (doc) => {
    doc._select = 'Y'
    this.added(collName, doc._id, doc)
  }
...
}

Now on the client you easily differentiate between docs coming from either publication.


#5

Indeed. Merge box is a feature, not a flaw!

For such a scenario as OP is describing, it may be appropriate to break isomorphisicity and simply create an additional client side collection.


#6

Could something like https://atmospherejs.com/meteorhacks/search-source help?