Background - I have a collection with 7,933 documents. I'm testing on a local host with a local mongodb server running. I also get the same issue on localhost with a remote mongodb server.
Problem - When running a simple db.collection.find().count(), meteor returns 0 documents found at first, incrementing to 7,933 over the course of about 6 seconds.
Console -
Count at: 1402440532060 is 0
Count at: 1402440533061 is 322
Count at: 1402440534064 is 1293
Count at: 1402440535087 is 2799
Count at: 1402440536557 is 4666
Count at: 1402440537696 is 7933
Count at: 1402440538697 is 7933
Count at: 1402440539699 is 7933
Count at: 1402440540701 is 7933
Count at: 1402440541702 is 7933
App Structure -
/client/foo.html
/clint/foo.css
/client/foo.js
/lib/collections.js
/server/server.js
Code -
/lib/collections.js:
fooCollection = new Meteor.Collection('fooCollection');
/server/server.js:
Meteor.publish("fooDB", function () {
return fooCollection.find();
});
/client/foo.js:
Deps.autorun(function() {
Meteor.subscribe("fooDB");
});
var counter = 0;
var i = setInterval(function(){
var ts = Date.now();
console.log("Count at: " + ts + " is " + fooCollection.find().count());
counter++;
if(counter === 10) {
clearInterval(i);
}
}, 1000);