Update nested child elements with jenssegers/laravel-mongodb

Viewed 55

I have a document with child elements of items like so

"bar" : "d bar",
"items" : [ 
        {       
            "message" : "one",
            "display" : "true",
            "type" : "text"     
        } 
        {       
            "message" : "one2",
            "display" : "true",
            "type" : "text2"     
        }
        {       
            "message" : "one2",
            "display" : "false",
            "type" : "text3"     
        }
]

I want to update the fields that are 'one2' in the array to 'one22'. I'm writing this command, but it only updates the first value.

Bars::where('bar', 'd bar')
    ->where('items.message', 'one2')
    ->update(['items.$.message' => 'one22']);
0 Answers
Related