[
{
"_id": "1",
"checklists": [
[1, 3, 5]
]
},
{
"_id": "2",
"checklists": [
[2, 4, 6]
]
},
{
"_id": "1",
"checklists": [
[7, 9]
]
},
]
预期按 id 合并后数据如下:
[
{
"_id": "1",
"checklists": [
[1, 3, 5, 7, 9]
]
},
{
"_id": "2",
"checklists": [
[2, 4, 6]
]
}
]
备注:不关心数组内顺序,相当于 Set,合并去除重复元素,顺序不重要。
试试添加上如下代码 .group({ // 按照_id分组,将checklists拼接到一起,形成新的数组 _id: '$_id', checklists: $.addToSet('$checklists') })
可以通过聚合查询查出来【mergeObjects】
https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/command/aggregate/AggregateCommand.mergeObjects.html