Update array field

I’ve created an array
“reviews” : [
“rating” : 5.0,
“reviewer” : “Spencer H.”,
“date” : ISODate(“2019-07-04T08:57:01.822Z”),
“text” : “Some review text”

and try to update rating

    {"title": "The Martian"},
    {$set : {"reviews.$[element].rating" : 6.0}},
    {arrayFilters: [{"element": 0}]}

response is

“acknowledged” : true,
“matchedCount” : 1.0,
“modifiedCount” : 0.0

So the question is how to update a field for some particular array element?

Hey @Siarhei_32861

So this part of the docs

Specifically the info on the $ operator. You would include in the query, conditions to target the movieDetail doc and the element in the array, then use reviews.$.rating in the update object.

Also Welcome to Mongo University and best of luck with the rest of the class! :slightly_smiling_face:


Pl Add you are Query in $ operator and Pl learn Mogodb