如何在 mongoose 中查询今天(从 00h:00m:00s 到现在)created
的所有数据?
{
"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)
}
最佳答案
只需创建一个包含今天开始的 Date
对象,然后在查询中使用它:
var now = new Date();
var startOfToday = new Date(now.getFullYear(), now.getMonth(), now.getDate());
MyModel.find({created_on: {$gte: startOfToday}}, function (err, docs) { ... });
关于mongoose - 如何查询今天 `created`所在的所有数据(从00h :00m:00s to now) in mongoose?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21795631/