{
"offers" : [
{
"name" : "min",
"prices" : [
8, 15, 18
]
},
{
"name" : "max",
"prices" : [
9, 11, 18
]
}
],
"nl" : [
2, 4, 6, 7
]
}
[
{
$set: {
offers: {
$cond: {
if: {
"nl": {$in: [7]}
},
then: {
$concatArrays: ["$offers", []]
},
else: {
$concatArrays: ["$offers", [{
"name" : "minimal",
"prices" : []
}]]
}
}
}
}
},
]
[
{
$set: {
offers: {
$cond: {
if: {
$in: ["$nl", 7]
},
then: {
$concatArrays: ["$offers", []]
},
else: {
$concatArrays: ["$offers", [{
"name" : "minimal",
"prices" : []
}]]
}
}
}
}
},
]
$in 聚合采用以下语法:
{ $in: [ <expression>, <array expression> ] }
您需要反转 $in 条件。像这样:
$in: [7, "$nl"]