How to query all data where created is today (from 00h:00m:00s to now) in mongoose?
{
"user": ObjectId("52fe173148ee58a0180c1d77"),
"caption": "aaaa",
"created": ISODate("2014-02-14T16:04:57.98Z"),
"__v": NumberInt(0)
}
{
"user": ObjectId("52fe173148ee58a0180c1d77"),
"caption": bbb",
"created": ISODate("2014-02-14T14:10:27.986Z"),
"__v": NumberInt(0)
}
Just create a Date object that contains the start of today and then use that in the query:
var now = new Date();
var startOfToday = new Date(now.getFullYear(), now.getMonth(), now.getDate());
MyModel.find({created_on: {$gte: startOfToday}}, function (err, docs) { ... });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With