Created
February 8, 2016 20:07
-
-
Save narainsagar/9b4b51d1efce4a16c32d to your computer and use it in GitHub Desktop.
Finding number of records where date is in date range?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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