This is somewhat similar to my previous question How to update mongodb array values
"Fiction" : [
{
"SNo": "1",
"authorName" : "Enid Blyton",
"bookSeries" : "Secret Seven series",
"bookName" : [{"Title": "Secret Seven Adeventure", "Amount": 115},
{"Title": "Well done Secret Seven", "Amount": 135}]
},
{
"SNo": "2",
"authorName" : "Enid Blyton",
"bookSeries" : "Mystery series",
"bookName" : [{"Title": "Burnt Cottage", "Amount": 150},
{"Title": "Vanished Prince", "Amount": 140}]
}
]
I wish to update the Amount: 115
to Amount: 135
.
From the solution to the earlier question I tried it by doing something like this
db.Fiction.update({"Fiction.SNo": "1","Fiction.bookName.$.Title": "Secret Seven Adeventure"},{$set:{"Fiction.bookName.$.Amount": 135}})
but I am getting WriteResult({ "nMatched" : 0, "nUpserted" : 0, "nModified" : 0 })
Can anyone tell me why I am getting like this
Edit:
The suggested answer works only if the index of the array is known.
But in my case the index
of the array is not known.