Meteor.publish("OrdersGroupJoinDraws",function(){
let self=this;
let pipline=[.....];
Orders.aggregate(pipline).forEach((item)=>{
self.added("OrdersJoinDraws",item._id+"",item);
});
self.ready();
});
client
Meteor.subscribe("OrdersGroupJoinDraws",function(){
Orders.find().fetch(); // result is [];
OrdersJoinDraws.find().fetch(); // result is [];
});
Have you tried putting some console.logs within the server’s forEach block to see if any records are added as a result of the aggregation?
I’ve not got any experience of using aggregate within publications, I’ve only used it within methods.
One thing to note is since Meteor 1.7.0.1 the aggregate function returns an AggregationCursor instead of an array, so now it’s necessary to use toArray() on the result. Read more here: https://docs.meteor.com/changelog.html#v170120180529
I found that the example code in the changelog above didn’t work for me because toArray() also returns a promise. Instead I did this:
Sorry, I’m not familiar with publishing the result of aggregations - I’m not even sure if the result is reactive. In my case I didn’t need reactivity on the result so I used a method to send the array to the client.
If you do not want reactive aggregations (e.g. you’re using Meteor methods), you should really use the underlying MongoDB methods, rather than rely on an unmaintained package which does not take account of changes in the MongoDB library, and just wraps those methods in a small amount of Meteor sugar.
Alternatively, if you do want reactive aggregations (pub/sub), you will find an atmosphere package to be a simpler way to achieve what you want. Look at tunguska:reactive-aggregate for a modern (ES7) way to do this in Meteor.