我正在尝试使用MongoDB中的聚合函数获取一些记录,但它显示以下无效运算符$slice
:
db.getCollection('test').aggregate( [
{ $match: { 'subjectId': '123' } },
{ $sort: { 'assessmentDate': -1 } },
{ $group: { '_id': '$area', 'docs': { $push: "$$ROOT" } } },
{ $project: { docs: { $slice: ["$docs", 1, 1] } } },
])
Error("Printing Stack Trace")@:0()@src/mongo/shell/utils.js:37([objectArray])@src/mongo/shell/collection.js:866
@(shell):1
uncaught exception: aggregate failed: {
"errmsg" : "exception: invalid operator '$slice'",
"code" : 15999,
"ok" : 0
}
MongoDB 版本 3.0.9
$slice
是 MongoDB 3.2 版本开始支持的功能。 - Shaishab Roy