Hi MongoDB community,
I’m pretty new to mongoDB, so let me apology first for any silly issues I’ll raise to you.
I’m trying to add a ‘calculated’ field (field13 = field1 * field3) into an array (Array) of documents.
That’s the final document I’m trying to get:
{"_id":"123",
"field0":10,
"field1":10,
"Array":[{
"field2":"test",
"field3":20,
"field13": field1*field3
}]
}
To do so, I’m using $addfields and $multiply in an aggregation stage:
[{$addFields: {"Array.field13": {$multiply:["$Array.0.field3","$field0"]}}}]
Despite many attempts, I always get the error: $multiply only supports numeric types, not array. On the contrary, if I use
[{$addFields: {"Array.field13": {$multiply:["$field1,"$field0"]}}}]
everything works fine.
What am I doing wrong in referring to the value of field3?
Thank you in advance for any help.
MC