Alternative to group by for cosmos db

Author: Slicc

Given that cosmos db does not support group by, what is a good alternative to achieve similar functionality:

Select sum(*) , groupterm from tble group by groupterm

Can I efficiently achieve this in a cosmos stored procedure?

Originally Sourced from: https://stackoverflow.com/questions/45270125/alternative-to-group-by-for-cosmos-db