Publish meteorhacks:aggregate not working in my project


#1

Hi, I need someone help to solve my problem. I have create some code using meteorhacks but i still cannot display the result. Can someone help me. This I sharing my code:
//publish
Meteor.publish("profil", function() { var groupedKategori = Profil.aggregate({ $group: { _id: "$kategori", count:{$sum:1}}}); groupedKategori.forEach(function(kategori) { console.log(kategori); }); });
//html
` {{#each groupedKategori}}


{{kategori}} {{/each}}`

//js
Template.laporankategori.helpers({ groupedKategori: function() { var currentUserId =this._id; return Profil.find({kategori: currentUserId}); }, });


#2

Aggregations don’t work very well in publications. It might be better to do that sort of thing in a background job, and insert that into some other collection that you can just publish reactively more easily.

I’d recommend learning Meteor its pub-sub system a little before trying stuff like this.


#3

You can use this reactive aggregate package. It uses publication and stores the aggregated data in client collection. Read this blog post to see how the author uses the package.