I have a document that looks like the following
{
"list" :{
"friends": [
{
"Name": "John",
"Contact": "xyz",
"Code": "B"
},
{
"Name": "Smith",
"Contact": "abc",
"Code": "A"
}
]
}
}
I'm trying to delete a field using the $unset
operator based on a filter. My code looks like:
result = db.collection.update_many({"list.friends.code": "A"},
{"$unset": {"list.friends.$.Name": "", "list.frieds.$.Contact": ""}})
However, I get pymongo.errors.WriteError: Invalid BSON field name 'list.friends.$.Name'