Issue with $group on an object field
Closed this issue · 1 comments
A simple count with mongo/jongo works perfectly :
jongo.getCollection("countries").aggregate("{$group:{
_id:'$_id', 'count':{$sum:1}}}")
(don't question the purpose, I use id as a var because it can work with any data)
I get a count of one for each object, which is expected :
[{"_id":"0000000000000000000000C2","count":1},{"_id":"0000000000000000000000C3","count":1},{"_id":"0000000000000000000000C4","count":1},{"_id":"0000000000000000000000C5","count":1},{"_id":"0000000000000000000000C1","count":1}]
But as soon as a use an object as an_id :
jongo.getCollection("countries").aggregate("{$group:{
_id:{'foo':'$_id'},'count':{$sum:1}}}")
Now I get 0 as count :
[{"_id":{"foo":"0000000000000000000000C1"},"count":0},{"_id":{"foo":"0000000000000000000000C2"},"count":0},{"_id":{"foo":"0000000000000000000000C3"},"count":0},{"_id":{"foo":"0000000000000000000000C4"},"count":0},{"_id":{"foo":"0000000000000000000000C5"},"count":0}]
Which is not what is expected, and not was you get if you use the same query in mongo.
In fact it was a problem with Fongo, not Jongo.