最新下载
热门教程
- 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);
}
}
相关文章
- 第五人格佣兵护腕怎么用 第五人格佣兵护腕教学 04-28
- 崩铁星穹列车年度开拓报告活动怎么玩 星穹列车年度开拓报告网页活动介绍 04-28
- 逆水寒手游五子棋残局三十二怎么过 04-28
- 崩坏星穹铁道齐颂给谁用 04-28
- 火影忍者手游旋涡鸣人仙人模式怎么玩 04-28
- 原神怎么破坏磐键 原神破坏磐键的方法 04-28