如何在mongoose中查询created
今天(从00h:00m:00到现在)的所有数据?
{
"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)
}
答案 0 :(得分:2)
只需创建一个包含今天开头的Date
对象,然后在查询中使用该对象:
var now = new Date();
var startOfToday = new Date(now.getFullYear(), now.getMonth(), now.getDate());
MyModel.find({created_on: {$gte: startOfToday}}, function (err, docs) { ... });