I can't write a query that would update a value of an array that is inside of an object:
Let's say I have a collection that has document entries with the structure like below (There are 2 entries in the example but actually there are a few thousand that I need to update in my db)
/* 1 */
{
"name" : "Bob",
"info" : {
"species" : "human",
"addresses" : [
"one",
"two"
]
}
},
/* 2 */
{
"name" : "John",
"info" : {
"species" : "human",
"addresses" : [
"two",
"three"
]
},
}
How can I update all documents in this collection so that all addresses in info.addresses array with value one would be changed to have value four?
Examples in mongo db documentation solve such cases when arrays are not inside objects, but I can't make them work with arrays inside objects
Example - this query should update all info.addresses arrays for all documents and change the entry values from one to four
db.getCollection('test').update({"info.addresses": "one"},{ $set: { "info.addresses.$" : "four" } })