'Is there an option to make updateMany() specify which single document failed while being updated?

I am using mongodb and i have a list of orders documents that I want to update but some of them have null values on some parameters.

If I want to update a document that has “parameter.subparameter” in null in the current object that is being updated, the updateMany() will fail in that case.

var orders = [
    "ORDER_N_1",
    "ORDER_N_2",
    "ORDER_N_3"
]
try {
    var response = db.ORDER_COLLECTION.updateMany(
        {
            Order_Number: { $in: orders },
        },
        {
            $set: {
                "parameter.subparameter":"1"
            },
        }
    );
} catch(error) {
    print(error)
}

    
print("response: "+JSON.stringify(response, null, 2))

this is the response i get from the updateMany():

response: {
    "acknowledged": true,
    "matchedCount": 2,
    "modifiedCount": 2
}

As we can see, we have 3 objects to be updated but just only 2 were processed. All 3 objects match but as we encounter an error, the execution stopped so I want to know which document failed.

I tried looking for the documents once the updateMany() completes to see the value changed but i want an options that reduces database hits if is possible. I want to also note that I have read the UpdateMany() method documentation looking for an option to make it more "vervose" but doesn't seem to be posible

So my question is: Is there an option to make updateMany() or some other update (in bulk) method specify which document failed while being updated?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source