【发布时间】:2019-04-04 22:02:11
【问题描述】:
我正在尝试从数组中删除一个空元素,在投影中,尝试使用 $reduce
输入:["foo", "bar", null]
输出:["foo", "bar"]
$project: {
"newArray": {
$reduce: {
input: "$arrayInput",
initialValue: [],
in: {
$concatArrays: [
"$$value",
{
$cond: {
if: { $eq: [ "$$this", null ] },
then: [],
else: ["$$this"]
}
},
]
}
}
}
}
【问题讨论】:
-
您能否也展示样本集合以及您想要的输出
标签: arrays mongodb aggregation-framework projection