data: [
{
_id: '1',
schoolName: '学校1',
academyList: [
{
academyId: '1',
academyName: '学院1',
majorList: [
{
majorId: '1',
majorName: '专业1',
majorBookList: [],
},
]
},
{
academyId: '2',
academyName: '学院2',
majorList: [
{
majorId: '1',
majorName: '专业1',
majorBookList: [],
},
{
majorId: '2',
majorName: '专业2',
majorBookList: [],
},
]
},
],
},
{
_id: '2',
schoolName: '学校2,
academyList: [],
},
]
https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/command/aggregate/AggregateCommand.filter.html
db.collection('school')
.aggregate()
.match({
schoolName: '学校1'
})
.project({
academyList: $.filter({
input: '$academyList',
as: 'item',
cond: $.eq(['$$item.academyName', '学院2'])
})
})
.end()