可能您的某些查询与任何内容都不匹配。这就是为什么它返回不明确的结果。但还有另一个问题。这i异步回调中的内容可能不是您所期望的。并且可能等于月数长度。为了保持不变i你应该使用类似的东西:
var months = ['jan','feb','march','april','may','june','july','august','sep','oct','nov','dec']
for(var i=0; j=months.length,i<j; i++){
(function(i) {
var start = scope.getCurrentUTS(new Date(2013, i, 1));
var end = scope.getCurrentUTS(new Date(2013, i, 31));
var query = {};
query["stamps.currentVisit"] = {
"$gte" : start.toString(),
"$lt" : end.toString()
};
//connect to mongo and gets count coll.find(query).count(); working fine
mongoDB.getCount(query,function(result) {
console.log(result,i);
});
})(i);
}
还有这个
for(var i=0; j=months.length,i<j; i++){
可能只是:
for(var i=0; i<months.length; i++){