why I write body function with string? because in Golang I can’t use code for bson, so I must use function , the syntax above is I run on command line mongo cli to try there first then implement to my Go app
the error I got is
The dollar ($) prefixed field '$function' in 'tree.$function' is not valid for storage
anyone has same problem ? or I did wrong to use $function operator ??
The function operator requires mongodb 4.4,and it is an aggregation operator.
To use it on update,you have to use a pipeline,and aggregation operators.
(you use the $set update operator,not the $set($addField) aggregation operator)
Also to use the pipepile,your driver must support mongodb >= 4.2,and provide
a update method to accept a pipeline as argument.
Pipeline updates are different,but here looks like that just adding a [ ]
in the update part will work,if your driver supports it.
I am using Mongo Atlas and I am sure it gonna valid for using $function, and in my mongo cli I login as username on Mongo Atlas, can u give me example for update query with $function ? because the example on documentation only for query find data ,? @Takis
I tested on updating array also,its the same way,it worked fine,i used push.
This is how it works,but pipeline update are different from the old updates way.
With pipeline the result of the pipeline is the new document you want.