Codeigniter MongoDB扩展之使用Aggregate实现Sum方法
2024-10-20 16:17:50
本篇文章由:http://xinpure.com/codeigniter-mongodb-extension-using-aggregate-sum-method/
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);
}
}
最新文章
- 【JUC】JDK1.8源码分析之CountDownLatch(五)
- php识别中文编码并自动转换为UTF-8
- 用wireshark抓包分析TCP三次握手、四次挥手以及TCP实现可靠传输的机制
- BZOJ1727 [Usaco2006 Open]The Milk Queue 挤奶队列
- 小巧的http live streaming m3u8播放器
- eclipse提交本地项目到github
- Microsoft Visual C++ 不支持long long
- HTML form表单回车触发提交
- epoll 实现回射服务器
- 【win7】安装php7.3及扩展
- 判断是手机请求还是pc请求
- Codeforces 893A:Chess For Three(模拟)
- python 数据类型 之 字符串 拼接 方法 以及效率问题
- Where To Buy -- proposed by Renqian Luo
- 前端内容安全策略(csp)
- Python Flask 多环境配置
- poj1836 Alignment
- Unhandled rejection RangeError: Maximum call stack size exceededill install loadIdealTree
- Android 数据加密算法 Des,Base64详解
- 201621123023《Java程序设计》第12周学习总结