最新下载
热门教程
- 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);
}
}
相关文章
- dnf清澈的迷雾晶体用途详解 12-16
- 哔哩哔哩官网网页版官方入口-哔哩哔哩网页版直播互动专区 12-16
- 魔兽世界怀旧服Plus灰谷战场声望最新速刷方法 12-16
- 蛋仔派对云游戏秒玩入口-2026全新蛋仔派对网页版即点即玩地址汇总 12-16
- 魔兽世界怀旧服Plus战歌峡谷声望速刷攻略 12-16
- 番茄小说免费版畅读入口-番茄小说免费版极速轻量阅读入口 12-16