开发者

mongo group with order

开发者 https://www.devze.com 2023-03-01 04:41 出处:网络
i try to run such code $collection->group(array(\'goods_id\'=>1, \'server_id\'=>1), array(\'coun开发者_如何学JAVAt\' => 0, \'ip\'=>\'\', \'date\'=>\'\'), \'function (obj, prev) { pr

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:

  1. Sort the result of the group query in your code ('client side')
  2. Run a MapReduce and run a query, with sort(), on the collection that the MapReduce outputs
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号