MongoDB Update Strange Behavior

Hi,

Let’s say i have a basic document in MongoDB:
{
“_id”: {
“$oid”: “672018b783259ec48fbbba00”
},
“field1”: “Start”,
“field2”: “Start”,
“Object”: {
“ObjField1”: “Start”,
“ObjField2”: “Start”
}
}
In the following scenario, I want to update the document:



I use a special data structure to update, limited to the fields I want to update, but if I use the full data structure, it is the same.
As a result, I obtain this document:
{
“_id”: {
“$oid”: “672018b783259ec48fbbba00”
},
“field1”: “bidule”,
“field2”: “Start”,
“Object”: {
“ObjField2”: “truc”
}
}
You can see 2 different behaviors here:
If the data field is at the root level, it updates only the ones that needs to be updated. Here, field2 keeps its original value.
The ones that are inside an object and not updated are deleted.

How to avoid that ?

Thanks

I’ve got the same problem - it’s trashing deleting objects , field in the root are fine

did you get a solution ?