Hi,
I try to explain better. Let's say I have a doc like this:
{
"_id" : ObjectId("4f7d6606eaf4566192d7c923"),
"x" : [
{
"a" : "1",
"value" : 2
},
{
"a" : "2",
"value" : 2
},
{
"a" : "2",
"value" : 3
}
]
}
I'd like to update the value field of the second x element having a= 2.
By doing db.prova.update({"x.a":"2"},{$set:{'x.$.value':4}}) I see the first element is updated.
"_id" : ObjectId("4f7d6606eaf3806192d7c923"),
"x" : [
{
"a" : "1",
"value" : 2
},
{
"a" : "2",
"value" : 4
},
{
"a" : "2",
"value" : 3
}
]
I would like to avoid to extract the array, change it at application level, and then update he entire x field.
Could someone suggest a way to do it directly via mongo?
Thanks in advance to anyone who will answer,
bye