I have a document with nested objects in the following format:
{
...
search_preferences: {
...
bad_job_titles: []
}
}
Now, we update the nested field using the update_one method and $set operator.
db[collection].update_one({"id": id}, {"$set": {"search_preferences.bad_job_titles": ["xyz"]}})
It works mostly, but sometimes in production we are seeing documents where instead of updating the bad_job_titles, there’s a separate field in the document as “search_preferences.bad_job_titles” in the follow format:
{
...
search_preferences: {
...
bad_job_titles: []
},
search_preferences.bad_job_titles: ["xyz"]
}
I have been scratching my head, but not sure what’s happening here, and why it would happen only to some documents.