0
我有一群这样的:
{
"$group": {
"_id": "$conversationId"
"conversation": {
"$push": {"from": {
"firstName": "$fromObj.firstName",
"lastName": "$fromObj.lastName",
"title": "$fromObj.title",
"picture": "$fromObj.picture"
}
, "to": {
"firstName": "$toObj.firstName",
"lastName": "$toObj.lastName",
"title": "$toObj.title",
"picture": "$toObj.picture"
}
, "content": "$content",
"_id": "$_id",
"conversationId": "$conversationId",
"unreaded": "$unreaded"
}}
}
}
里面$push
一部分,我需要推刚刚过去的5个项目我该怎么办呢?这将是理想的,如果可以直接将$ limit添加到$ push任何解决方案吗?
你尝试在聚合管道的下一部分中启用“切片”以限制它们。请参阅https://docs.mongodb.com/manual/reference/operator/aggregation/slice/ – raj
[Mongodb聚合管道如何限制组推送]可能的副本(http://stackoverflow.com/questions/24594049/mongodb -aggregation流水线知识到极限一组推) – styvane