Codeigniter MongoDB扩展之使用Aggregate实现Sum方法
以下就是我在使用 Codeigniter 的 MongoDB 扩展时,添加的一个扩展
就是使用 MongoDB 的 Aggregate 实现 Mysql 中的 Sum 方法
/* Controller.php */
$option = array (
array (
'$match' => array (
'match_1' => 'value_1',
'match_2' => 'value_2'
)
),
array (
'$group' => array (
'_id' => null,
'sum_1' => ['$sum' => '$amount_1'],
'sum_2' => ['$sum' => '$amount_2'],
'sum_3' => ['$sum' => '$amount_3']
)
)
);
$result = $this -> mongo_db -> aggregate('collection', $option);
/* Mongo_db.php */
public function aggregate ($collection, $option = array())
{
try {
return $this -> db -> {$collection} -> aggregate($option);
}
catch (Exception $e) {
show_error("Unable to aggregate Mongo Databases: {$e->getMessage()}", 500);
}
}
您可能感兴趣的文章:
CodeIgniter的基本配置说明
CodeIgniter框架实例之过滤HTML危险代码
NoSQL数据库之MongoDB入门详解
CentOS 下三种 PHP 拓展安装方法
ci和thinkphp5哪个好
php主流框架有哪些?
安装与配置MongoDB数据
windows x86下安装mongodb且配置自动运行
FreeBSD下安装MongoDB数据库的方法
php使用ftp下载文件的简单例子