| | |
| | | } |
| | | |
| | | /** |
| | | * 聚合 |
| | | * @param [type] $colName [description] |
| | | * @param [type] $params [description] |
| | | * @return [type] [description] |
| | | */ |
| | | public function aggregate($colName, $params){ |
| | | $col = $this->_getCol($colName); |
| | | // 自动处理 '_id' 字段 |
| | | //$query = $this->_parseId($query); |
| | | $result = $col->aggregate($params); |
| | | |
| | | return $result['result']; |
| | | } |
| | | |
| | | /** |
| | | * 统计文档记录数 |
| | | * |
| | | * @param string $colName 集合名 |
| | |
| | | // 解析数据组中的'_id'字段(如果有的话) |
| | | private function _parseId($arr){ |
| | | if(isset($arr['_id'])){ |
| | | $arr['_id'] = new MongoId($arr['_id']); |
| | | try{ |
| | | $arr['_id'] = new MongoId($arr['_id']); |
| | | } |
| | | catch(MongoException $ex){ |
| | | die('非法的对象id'); |
| | | } |
| | | } |
| | | return $arr; |
| | | } |