最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Codeigniter MongoDB扩展之使用Aggregate实现Sum方法
时间:2022-06-25 00:50:25 编辑:袖梨 来源:一聚教程网
以下就是我在使用 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);
}
}
相关文章
- 人类黎明兑换码是什么 人类黎明最新2025兑换码一览 10-16
- 王者荣耀限时点券可以和点券一起用吗-限时点券叠加点券使用规则 10-16
- 我的世界基岩版网页版在线玩入口 mc基岩版官方网页在线游玩介绍 10-16
- 狂野星球复仇记兑换码分享 狂野星球复仇记最新2025兑换码大全 10-16
- 种呱得呱兑换码是什么 种呱得呱最新2025兑换码一览 10-16
- 辉烬水队阵容搭配攻略 10-16