Mongodb update level 3 or above cannot be deleted

 Project.updateOne(r, {
    $pull: {
        thunder2: {
            files: {
                _id: "5ab362d446f15936bcea7dd3"
            }
        }
    }
}, function(err, data) {
    if (err) {
        res.send("")
    } else {
        res.send("1")
    }
})
Feb.26,2021

can be done, but requires MongoDB 3.6support. Take a look at arrayFilters . For example:

// :
{
    "_id": ObjectId("5ab8c93249e47f821364662b"),
    "array": [{
        "array": [{
            "_id": ObjectId("5ab8c93249e47f821364662a")
        }]
    }]
}
// :
db.test.update({
    "array.array._id": ObjectId("5ab8c93249e47f821364662a")
}, {
    $pull: {
        "array.$[elm].array": {
            _id: ObjectId("5ab8c93249e47f821364662a")
        }
    }
}, {
    arrayFilters: [{
        "elm.array._id": ObjectId("5ab8c93249e47f821364662a")
    }]
})
Menu