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