db.nestedUpdate.updateMany({}, {
$set: {
'arr_1.$[idx0].c.$[idx1]': 1
}
}, {
arrayFilters: [
{
// idx0 满足条件: 需存在 c 字段
'idx0.c': {
$exists: true
},
'idx0.a': 1,
},
{
// idx1: 满足 值为 111
'idx1': 1111
}
]
});
// 或
db.nestedUpdate.updateMany({}, {
$set: {
'arr_1.$[idx0].c.$[idx1]': 1
}
}, {
arrayFilters: [
{
// idx0 满足条件: 需存在 c 字段
idx0: {
c: {
$exists: true
},
a: 1
}
},
{
// idx1: 满足 值为 111
'idx1': 1111
}
]
});