Hello
Is it possible to access the state when grouping?
Its very useful in situation where what i will do depends no only by the document,
but also from what i have already calculated
For example in the bellow, how to access the already summed?
For example here i add 1, but what if i wanted to add 0.5, if sum got big > 10k,
and 0.2 if sum got >20k etc (its so common useful thing)
aggregate(
[{"$group": {"_id": null, "count": {"$sum": 1}}}])
I know that $accumulator
user-defined way to group allows us to access the already groupes, but can we do the same with not user defined ones? i havent found anything in documentation, like a system variable like $$ACCVAL
or something.
Another solution that i thought was using $reduce
, to keep the state, but this cannot work because of 16MB limitation, we cant just put a big collection to an array, do the reduce ,and then unwind, we will hit the limit.
Accessing the state is so useful and common , if its not supported is there a way to add it?
Thank you