BasicDBObject key = new BasicDBObject("ip",true);
BasicDBObject initial = new BasicDBObject("count",0);
BasicDBObject cond = 。。。。
String reduce = "function(obj,prev){prev.count+=1}";
String finalize =?????
col.group(key,initial,cond,reduce,finalize);
最后的结果,我想要count
数量从大到小排列,并且只取前五个,能用finalize
实现吗?具体怎么写函数呢??或者能用什么方法实现????
To be honest, group-by under mongo is quite troublesome. Native mongo statement, aggregate query through pipeline
term: The name of the collection you want to query
$match: Matching conditions, optional
$limit: Number of results, optional
$group: Aggregation rules
$sort: Query The results are sorted, -1 means descending order
http://docs.mongoing.com/manual-zh/reference/operator/aggregation.html#aggregation-pipeline-operator-reference
Use aggregate for group calculation and sorting.
Simple example
See http://docs.mongodb.org/manual/reference/command/aggregate/