Dedikisme's Blog

Ngeblog biar dibilang eksis

MeteorJS: Overcoming Slow Problem Solving Due Count Large Data

I have large data on my app, but if I execute Collection.find().count() many times on google chrome console, the results are increasing until reached real total data, so how to count data faster as I execute ‘db.getCollection(‘books’).find().count()‘ on mongo console?

my script before: http://meteorpad.com/pad/rfoeDhdzepNubnnTe/Count%20Data1

Explanation: minimongo synchronizing the data from the server to the client, which takes the longer the more documents you have. The size of the documents also matters.

for example, I have a collection with a lot of large documents in it. When I want my client to have access to that collection, I only sync the title field. When the client needs access to the entire document, it will get published it in it’s entirety. In order to get the total number of books, you would need a method

1
2
3
4
5
Meteor.methods({
 numberOfBooks: function() {
   return Books.find().count();
 }
});

then use reactive variable, for simple way you can add Meteor Reactive Methods

1
meteor add simple:reactive-method

and add to the client d

1
2
3
4
5
Template.hello.helpers({
  numberOfPlayers: function(){
  return ReactiveMethod.call('numberOfPlayers');
  }
  });

Thanks to jamgold and Google Translate

Comments