I have a very very simple aggregation command I wrote and executed from the MongoDB shell, using the db.<collection>.group() interface. It worked flawlessly and I got the expected results. I then try to execute the same aggregation command via the 'cmd' format (in order to execute it over the Sleepy Mongoose interface via CURL) and it executed - only the aggregations all came back as '0'. Same data, same logic, etc.
My reduce function in both cases:
When using the cmd interface, 'res' is initialized to 0, the resultset will have the count field for the group by category set to 0.0. I tried to use the floatApprox method, setting the initial value of count to 1.0, etc but to no avail. res.count never increments. Also, while troubleshooting this, I noticed several JSON parsing issues related to the '+' operator...it seemed as if Mongo wasn't treating res.count as a long or float.
It works fine using the db.collection.group() interface.