If you're using Mongo version 4.2+ you can use pipelined updates like so:
db.collection.update({},
[
{
$set: {
data: {
$filter: {
input: "$data",
as: "datum",
cond: {
$ne: [
{
$arrayElemAt: [
"$$datum",
0
]
},
0
]
}
}
}
}
}
])
Mongo Playground
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…