However, for the value of code, I want to use the value of the object that matched (i.e. the object with parameters.name == "Andrew", which here is xxx.
Here’s a playground link to the problem Mongo playground Also, I am using a really old version (3.2) of MongoDb. It would be preferable if the solution worked with that. However, if that’s impossible, you can also suggest a solution with the minimum version that’s required.
Hello @Manak_Bisht, Welcome to the MongoDB community forum,
You have to do 2 queries in the 3.2 version, first, find the matching documents, and second, update query (you need to pass that property value from the above first query result).
You can try something like below example, i have not tested,
find the documents and use $ projection to return matching element from array
prepare the bulk update array for bulkWrite() method