I want to just put blank if the field is null.
Data:
"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"
}
}],
Input:
{
"$reduce": {
"input": "$history",
"initialValue": null,
"in": {
"$cond": {
"if": {
$eq: [
"$$this.status",
"Processed"
]
},
"then": "$$this.createdAt",
"else": "$$value"
}
}
}
}
Some of my data doesn't have a processed status in history array. I do not want to include null in my data. FYR: I'm doing this in mongodb charts.
question from:
https://stackoverflow.com/questions/65894505/remove-null-mongodb-aggregation 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…