I need the output of $group to be in the similar nested structure. I need their $avg values to be accumulated in the nested document itself.
When I try to use the field name as nested.field3 and nested.field4, it throws error.
The field name ‘nested.field3’ cannot contain ‘.’
Is there any operator that will let me do this?
PS: I dont want to add a project stage to do this.
The usage of the field name representation for the computed value in group aggregation cannot be of both these forms, and there are errors as seen below:
"nested.field3": { $avg: "$nested.field3" }
Error: "The field name 'nested.field3' cannot contain '.'"
nested: { field3: { $avg: "$nested.field3" } }
Error: "The field 'nested' must be an accumulator object"
You can work with this as follows, to get the desired result: