I have document like this,
{
"_id": {
"$oid": "5f33aca82b2fcf5324290ae1"
},
"active": true,
"addresses": [
{
"country": "IN",
"formatted": "xyz",
"locality": "San Francisco",
"postalCode": "7656",
"primary": true,
"region": "CA",
"streetAddress": "abc",
"type": "work"
},
{
"country": "US",
"formatted": "xyz",
"locality": "fdfdf",
"postalCode": "91608",
"primary": true,
"region": "CA",
"streetAddress": "def",
"type": "other"
}
]
}
The address attribute is multivalued , i want to update "streetAddress" of all address entries where "type"=="work".
But when i try this query below, "streetAddress" of all entries are getting updated.
mongo.db.test.update_one({'_id': ObjectId('5f33aca82b2fcf5324290ae1'), 'addresses.type':'work'}, {"$set":{'addresses.$[].streetAddress': "mno"}},upsert=True)
the result is,
{
"_id": {
"$oid": "5f33aca82b2fcf5324290ae1"
},
"active": true,
"addresses": [
{
"country": "IN",
"formatted": "xyz",
"locality": "San Francisco",
"postalCode": "7656",
"primary": true,
"region": "CA",
"streetAddress": "mno",
"type": "work"
},
{
"country": "US",
"formatted": "xyz",
"locality": "fdfdf",
"postalCode": "91608",
"primary": true,
"region": "CA",
"streetAddress": "mno",
"type": "other"
}
]
}
as you can see both entries are getting modified.
I am using flask-pymongo library.