Skip to content

Instantly share code, notes, and snippets.

@objectiveSee
Created May 8, 2014 21:31
Show Gist options
  • Save objectiveSee/194f05dcbb18edfa8cd8 to your computer and use it in GitHub Desktop.
Save objectiveSee/194f05dcbb18edfa8cd8 to your computer and use it in GitHub Desktop.
var countNumberActiveUsersInRangeXDaysAgo = function (range_length_in_days, numDaysAgo_start) {
var deferred = Q.defer();
var startDate = new Date();
startDate.setDate(startDate.getDate() - numDaysAgo_start);
var s = ObjectID.createFromTime(startDate.getSeconds());
var endDate = new Date();
endDate.setDate(endDate.getDate() - numDaysAgo_start + range_length_in_days);
var e = ObjectID.createFromTime(endDate.getSeconds()); // should i use seconds since 1970???
console.log('seconds = '+endDate.getSeconds());
var conditions = { _id: {$gte: s, $lt:e}};
console.log('conditions='+JSON.stringify(conditions));
User.count(conditions, function(err, count) {
if ( err ) {
deferred.reject(err);
} else {
deferred.resolve(count);
}
});
return deferred.promise;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment