【发布时间】:2018-07-26 10:37:41
【问题描述】:
我只想从集合中提取当天的 MONGODB 数据。 我已经尝试过这个请求:
db.hello.aggregate([
{ $match: { "name": "btb" } },
{ $where: function() {
today = new Date();
today.setHours(0,0,0,0);
return (this.date.getTimestamp() >= today)
}},
{ $group: {
_id: { articles: "$articles" },
total: { $sum: 1 }
}},
{ $project: {
"articles": 1,
"total": 1
}},
{ $sort: { "total":-1 } }
])
但我收到该消息错误:
####################################################################
Unable to execute the selected commands
Mongo Server error (MongoCommandException): Command failed with error 16436: 'Unrecognized pipeline stage name: '$where'' on server localhost:27017.
The full response is:
{
"ok" : 0.0,
"errmsg" : "Unrecognized pipeline stage name: '$where'",
"code" : NumberInt(16436)
}
####################################################################
【问题讨论】:
-
我想在 MONGODB 中提取当天的数据,比如今天:26-07-2018,我已经尝试过这个请求: 可以请多解释一下
-
@rayane-btb 您能否提供更多详细信息(例如示例文档和预期结果)?
-
想要从 mongodb 获得字段日期与当前日期匹配的结果