i try to run such code
$collection->group(array('goods_id'=>1, 'server_id'=>1), array('coun开发者_如何学JAVAt' => 0, 'ip'=>'', 'date'=>''), 'function (obj, prev) { prev.count++; prev.ip=obj.user_ip; prev.date=obj.time_download }')->sort(array('count'=>1));
without sort works, with sort not work any ideas?
MongoDB does not yet support grouping and ordering in a single query. Until it can, you can do two things:
- Sort the result of the group query in your code ('client side')
- Run a MapReduce and run a query, with sort(), on the collection that the MapReduce outputs
精彩评论