Home:ALL Converter>MongoDB update nested array

MongoDB update nested array

Ask Time:2012-06-29T20:09:43         Author:user50992

Json Formatter

I have a simple structure in mongodb, with nested array. How can I update searched value? I've seen examples using numbers something like this:

invited.0.used: true

but this is not what I'm searching for because I don't know where in my list is this element so how could I update array used to true where key is 84026702? What if I have 100 arrays in invited how to update where key is 43938432?

{
    "_id" : ObjectId("4fed972f61d69aa004000000"),
    "name" : "mezo",
    "invited" : [
            {
                    "key" : 40928710,
                    "used" : false
            },
            {
                    "key" : 84026702,
                    "used" : false
            }
    ]
}

Author:user50992,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/11261521/mongodb-update-nested-array
yy