public function test(){
$app_id=1;
$res= MongoClient::getInstance()->client()->callback(function (MongoClientDriver $driver) use($app_id){
$options =[
'group' => [
'ns' => 'ny_room_browse_record',
// '$reduce' => new MongoDB\BSON\JavaScript('function(doc, prev){prev.items.push(doc.FUserName);}'),
'$reduce' => 'function (obj, prev) {
if (prev.create_time_max < obj.create_time) {
prev.create_time_max = obj.create_time;
prev.room_name=obj.room_name;
prev.room_desc=obj.room_desc;
prev.room_pic=obj.room_pic;
prev.id=obj._id.toString().substr(10,24);
}
}',
'key' => [ 'room_id' => 1 ],
'initial' => ["room_name" =>'',"create_time_max"=> 0,'room_desc'=>'','room_pic'=>'','id'=>''],
'cond'=>[ 'wechat_user_space_id' => 1 ],
],
];
$driver->getDb();
$driver->collection = 'ny_room_browse_record';
$ret = $driver->group($options);
return $ret;
});
$this->writeJsonSelf(['code' => StatusCode::success,'msg' => 'success','data' => $res]);
}