如果该字段为空,我只想留空。
数据:
"history": [{
"status": "Not Processed",
"createdAt": {
"$date": "2021-01-26T00:16:26.018Z"
},
"updatedAt": {
"$date": "2021-01-26T00:16:26.018Z"
}
}, {
"status": "Processed",
"updatedAt": {
"$date": "2021-01-26T00:17:25.725Z"
},
"createdAt": {
"$date": "2021-01-26T00:17:25.725Z"
}
}],
输入:
{
"$reduce": {
"input": "$history",
"initialValue": null,
"in": {
"$cond": {
"if": {
$eq: [
"$$this.status",
"Processed"
]
},
"then": "$$this.createdAt",
"else": "$$value"
}
}
}
}
我的一些数据在历史数组中没有处理状态。我不想在我的数据中包含 null。FYR:我在 mongodb 图表中执行此操作。