How to write simial query using mongdoDb aggregation
select count(*) as ccount from a group by a.someField order by ccount desc limit 1
Using group function in mondoDb, I want to group my collection by specific key and return 1 row, which occurs more often
Code below in Java, return list, that was apply group by on field someField and return collection of elements, where every element has 2 fields, "someField" and "count" (number of occurrence) I would like to avoid second iteration on client side to find out maximum of counts
new GroupCommand(myCollection,
new BasicDBObject("someField ", true),
null,
new BasicDBObject("count", 0),
"function(key,val){ val.count++;}",
null);
In mongoDB 3 you can use limit and skip:
http://docs.mongodb.org/manual/reference/operator/aggregation/
Nothing like SQL's order or limit is available for MongoDB's group command. The aggregation framework in the current development release (version 2.1) provides $sort and $limit operators:
http://www.mongodb.org/display/DOCS/Aggregation+Framework