【发布时间】:2020-07-29 14:13:55
【问题描述】:
我有一个列表消息,格式如下:
[
{
"_id": 1,
"groupID": 1,
"content": "content 1",
"createAt": 1
},
{
"_id": 2,
"groupID": 1,
"content": "content 2",
"createAt": 2
},
{
"_id": 3,
"groupID": 2,
"content": "content 3",
"createAt": 3
},
{
"_id": 4,
"groupID": 2,
"content": "content 4",
"createAt": 4
},
{
"_id": 5,
"groupID": 2,
"content": "content 5",
"createAt": 5
},
{
"_id": 6,
"groupID": 2,
"content": "content 6",
"createAt": 6
}
]
如何获取每个组的最后一条消息(与“createAt”比较)?
预期结果:
{
"_id": 2,
"groupID": 1,
"content": "content 2",
"createAt": 2
}
{
"_id": 6,
"groupID": 2,
"content": "content 6",
"createAt": 6
}
【问题讨论】:
标签: mongodb mongoose mongodb-query aggregation-framework