Skip to content

Instantly share code, notes, and snippets.

@masylum
Created October 19, 2010 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masylum/634478 to your computer and use it in GitHub Desktop.
Save masylum/634478 to your computer and use it in GitHub Desktop.
Async with For Loop
var login_counts = [],
j = 30,
// functions scope
add_count = function (index, query) {
collection.find({date: query},function (err, cursor) {
cursor.count(function (err, count) {
login_counts[index] = count;
});
});
};
for (;j>0;j--) {
tday.setDate(tday.getDate()+1);
yday.setDate(tday.getDate()+1);
add_count(j, {'$gt':tday, '$lt':yday});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment