Meteor: Filter documents by their publication provenance on client side

90 Views Asked by At

I came along the following problem:

  • I have a custom server side publication "P1" which returns a set of documents from collection "C", the server is the only one able to build this subset

  • On my client I subscribed to 2 publications ("P1" and "P2") returning 2 subsets of the collection "C", they might overlap.

  • I would like to list on my client only the elements returned by the publication "P1" i.e. the one the server can only generate the set. The problem is that I am not able to use the regular find query to filter the collection "C" and get the subset "P1". This because only the server is able to do so arbitrarily.

How could I then filter on the client side a document according to its publication provenance ?

2

There are 2 best solutions below

0
On

Meteor will automatically publish the correct documents in a single instance (so they're not published twice).

Because of this the client will not actually be able to tell the difference as the server won't make it very clear that the collections overlap.

There is no other way than to use a method like Elizier suggests:

Meteor.methods({
    differences: function() {

        var queryOne = _(MyCollection.find({..}).fetch()).pluck("_id");
        var queryTwo = _(MyCollection.find({..}).fetch()).pluck("_id");

        var differences = _([queryOne, queryTwo]).difference();
        var intersection = _([queryOne, queryTwo]).intersection();

        return differences
    }
});
0
On

As far as I'm aware you can't directly do that.

A possible solution might be to use a Meteor method to request the ids you need for the publication, then make a subscription using those ids, and then you can filter client side using the list of ids you already have.