Skip to content

Instantly share code, notes, and snippets.

@narainsagar
Created February 8, 2016 20:07
Show Gist options
  • Save narainsagar/9b4b51d1efce4a16c32d to your computer and use it in GitHub Desktop.
Save narainsagar/9b4b51d1efce4a16c32d to your computer and use it in GitHub Desktop.
Finding number of records where date is in date range?
This is the easiest way you can:
var thisDate = ISODate("2016-01-07T00:00:00Z");
Model.find({
startDate: {
'$lte': thisDate
},
endDate: {
'$gte': thisDate
}
});
It will return all docs (in array) in which `startDate` greater than or equals to `thisDate` and `endDate` less than or equals to `thisDate`
For `counts` use `.length()` on your received collection which is array so .length() will return you count easily..
Hope this helps.
Cheers,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment