Count data from collection

Hi, anyone please i need you help. I have create code to count variable in collection. I can get the result when count one by one but not by group. Thats my code, I want to count this but the code not given any resut to me. I want the result like this:

PTR 1
KOM 4

This my code:
`









{{#each profil}}


{{/each}}
Jenis Peralatan Kuantiti
{{PTR}} {{KOM}}
`

//js
Template.laporankategori.helpers({ profil: function() { return Profil.find({kategori: { $in: ['PTR', 'KOM'] } }).count(); } });

You can use publish count package. https://atmospherejs.com/tmeasday/publish-counts

Beside use this pakage, can you suggest to me how to use a manually.

i think this package is easy to use. you dont have to write your own code all the times.
//publish

Meteor.publish("countProductByCategory", function(categoryId) {
  Counts.publish(this, 'productCount', Restaurant.Collection.Products.find({
    categoryId: categoryId
  }));
  this.ready();
});

//using in template helper

{{getPublishedCount 'productCount'}}

//using in js file

Counts.get('productCount')

Note: After finish publish you need to rerun your server.

1 Like