I am having following code in node.js.
var months = ['jan','feb','march','april','may','june','july','august','sep','oct','nov','dec']
for(var i=0; j=months.length,i<j; 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);
});
}
Problem : Being code is running async, last line of code is not running as expected.
output expected is
10 0
11 1
12 2
.......
........
40 11
but it is giving output as
undefined 11