Hello : )
I inserted those data,1 document and i tried to replace the existing fields,with a single value,
an array,and an onbject and i got un-expected for me results,i just wanted to replace the old value.
{
"mysingle1": 1,
"mysingle2": 1,
"mysingle3": 1,
"myarray1": [1,2],
"myarray2": [1,2],
"myarray3": [1,2],
"myobject1": {"afield": ""},
"myobject2": {"afield": ""},
"myobject3": {"afield": ""}
}
And i used $addFields.To always add a new field,that already existed.
Reading the documentatation from the IMPORTANT + example after
seemed that new field value,will replace the existing but this is not the case.
Sometimes it replaces,sometimes it updates,and the update result looks unexpected.
Maybe in the documentation somewhere it resolves it but this is why i thought it is always replace.
$addFields behaviour
single -> add single/array/document => replace
array -> add single/array => replace
array -> add document => update,all members of the array becomes that document
{"$addFields" : {"myarray3" : {"afield1" :""}}}
became
{"myarray3" : [{"afield1" :""} {"afield1" :""}]}
document -> add single/array => replace
document -> add document => update document,added becomes its member
{"$addFields" : {"myobject3" : {"afield1" :""}}}
became
{"myobject3" {"afield" "", "afield1" ""}}
Then i used the same but with $project,results was like addFields but
document -> add document => replace
This is complicated for me ,i just want to replace the value.
Without thinking what was there,and what i add.
Why it works this way?Where this helps?
Especially the update of the array with the document as all its members looks so un-expected.
There is a way to just replace the old field,and never update,using one stage?
Thank you.