Skip to content

Instantly share code, notes, and snippets.

@lwille
Created October 20, 2012 22:12
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lwille/3925008 to your computer and use it in GitHub Desktop.
Save lwille/3925008 to your computer and use it in GitHub Desktop.
pretty clean way of obtaining reactive item counts in meteor
Meteor.autosubscribe ->
Meteor.call 'getItemCount', Session.get('currentCustomer'), (err, count)->
Session.set 'itemCount', count
Template.foo.itemCount = ->
Session.get 'itemCount'
Meteor.methods
getItemCount: (customer)->
return Items.find(customer: customer).count()
@lwille
Copy link
Author

lwille commented Oct 20, 2012

As I explained in this answer on StackOverflow, you shouldn't use the pub-sub mechanism for counting on large datasets (thousands of docs). This new solution is amazingly fast and doesn't load any unneccessary document from the mongoDB.

@Charuru
Copy link

Charuru commented Feb 2, 2013

This is not real time?

@tamvm
Copy link

tamvm commented Nov 2, 2013

Just tried, but not work :(

@giantelk
Copy link

Side Note: Meteor.autosubscribe has been depreciated and replaced by Deps.autorun()
http://docs.meteor.com/#deps_autorun

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment