Hello : )
On the chapter Pipeline Optimization - Part 2,it says its good practice use array map,filter,reduce etc
instead of unwind group .
Is it possible to group an array using reduce(without unwind+group),in the general case?
For simple example (instead of numbers could be documents etc)
[1 2 3 1 2 10 2] to become {“1” [1 1] , “2” [2 2 2] ,“3” [“3”] , “10” [10]}
Also is it possible to reference a field,by constructing the reference inside the pipeline,
like concatStrings("$" “myfield”)?
If i could do the second,i could check if the member is key to the reduced map,and update it
but i cant construct the reference based on what i see in the reduce.
In functional languages this is so simple to do,but i don’t know how to do it in mongodb.
Thank you