我想在数组对象内的数据上聚合$ match:
{ example: [{target: "1"}] }
我尝试过$match
,$elemMatch
,$arrayEleAt
,但是我不知道如何编写正确的语法。
{ $lookup: { from: "example", localField: "user_id", foreignField: "user_id", as: "example" } },
{
$match: {
"start_date": { $gte: new Date(startDate) },
"end_date": { $lte: new Date(endDate) },
"type": Type,
"target": "1"
},
},
{ $sort: { startDate: 1 } },
答案 0 :(得分:1)
只需这样写:
{
$match: {
"start_date": { $gte: new Date(startDate) },
"end_date": { $lte: new Date(endDate) },
"type": Type,
"example.target": "1"
},
},