Hi guys,
is there any way to publish a collection and results of an aggregation query in same subscription?
Something like
return[
Collection1.find(…)
, Collection2.aggregate(…)
]
is not working as aggregation return an array and publication is supposed to return a cursor.
It seems, the only way to do that while keeping Collection1 results reactive, is to do something like that:
const handle=Collection1.find({}).observeChanges({
added: function(id, fields) {
self.added(“Collection1”, id, fields);
},
removed: function(id) {
self.removed(“Collection1”, id);
},
changed: function(id, fields) {
self.changed(“Collection1”, id, fields);
}
});const agg=Collection2.aggregate([…]);
agg.forEach(function(item) {
self.added(‘Collection2’, item._id, item);
});self.onStop(function() {
handle.stop();
});self.ready();
Any performance concerns with that approach? Any solutions besides that? Thank you!