I have an array tree and I want to update that array in my collection with this syntax
db.documents.updateMany(
{
companyId: ObjectId("5f29074048538b6403bc71ab",
tree: {
$in: [ObjectId("5f539bf696fa1748fa417b07")],
},
},
{
$set: {
tree: {
$function: {
body:
"function(t) { t.push(ObjectId('5f5494a1d708bda4988d75d4')); return t.filter(v => [ObjectId('5f539bf696fa1748fa417b07')].includes(v))}}",
args: ["$tree"],
lang: "js",
},
},
},
}
);
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 ??