Codeigniter MongoDB扩展之使用Aggregate实现Sum方法
本篇文章由: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);
}
}
Codeigniter MongoDB扩展之使用Aggregate实现Sum方法的更多相关文章
- Codeigniter MongoDB类库
安装方法:1.将mongodb.php 放到config目录2.将Mongo_db.php放到library目录 使用方法: $this->mongo_db->where_gte('age ...
- linux下为php添加mongodb扩展
基于本博客yum安装的lamp环境,phpize 位于 /usr/bin,php-config 位于/usr/bin,php.ini 位于/etc/ 1.首先从http://pecl.php.net/ ...
- windows10 php7安装mongodb 扩展
系统环境:win10家庭版Phpstudy2016 php7 1. 打开phpinfo 查看 nts(非线程) 还是 ts (线程),然后查看操作位数 注: 86 等于 32 位 ,和你的windo ...
- windows下安装MongoDB扩展和配置
windows下安装MongoDB扩展和配置 1.下载mongoDB扩展,根据当前php版本进行下载 地址如下:http://pecl.php.net/package/mongo 我本地php版本是 ...
- windows10 php7安装mongodb 扩展及其他扩展的思路
1. 打开phpinfo 查看 nts(非线程) 还是 ts (线程),然后查看操作位数 注: 86 等于 32 位 ,和你的windows系统64 or 32位无关.比如我的: 2. 下载对应的版本 ...
- windows php7 安装 mongodb 扩展
1. 打开phpinfo 查看 nts(非线程) 还是 ts (线程),然后查看操作位数 注: 86 等于 32 位 2. 下载对应的版本的php_mongodb.dll 文件下载链接: pecl m ...
- Linq聚合操作之Aggregate,Count,Sum,Distinct源码分析
Linq聚合操作之Aggregate,Count,Sum,Distinct源码分析 一:Linq的聚合运算 1. 常见的聚合运算:Aggregate,Count, Sum, Distinct,Max, ...
- Centos7.5 lnmp+mongodb扩展
安装NginxYUM源中没有Nginx,我们需要增加一个nginx的源nginx.repo # vi /etc/yum.repos.d/nginx.repo 源文件的内容 [nginx] name=n ...
- php mongodb扩展 其他扩展也类似
MongoDBPHP 扩展 本教程将向大家介绍如何在Linux.window.Mac平台上安装MongoDB扩展. Linux上安装 MongoDB PHP扩展 在终端上安装 你可以在linux中执行 ...
随机推荐
- Problem D: 判断上否上三角矩阵
#include<stdio.h> int main() { ][],i,j; while(scanf("%d",&n)!=EOF) { ; //flag用来做 ...
- WPF Interaction框架简介(一)——Behavior
在WPF 4.0中,引入了一个比较实用的库——Interactions,这个库主要是通过附加属性来对UI控件注入一些新的功能,除了内置了一系列比较好用的功能外,还提供了比较良好的扩展接口.本文这里简单 ...
- Describe in brief Databases and SQL Server Databases Architecture.
Databases- A database is a structured collection of data.- Database can be thought as simple data fi ...
- Visual Studio自动生成XML类和JSON类
Visual Studio 2013及以上版本提供了一个非常实用的功能.可以根据xml文档或json文档自动生成类.有了这个工具反序列化时就不用再手动写类并且实现了强类型操作. 步骤 1. 准备一份j ...
- 【spring colud】spring cloud微服务项目搭建【spring boot2.0】
spring cloud微服务项目搭建 =================================== 示例版本: 1.spring boot 2.0版本 2.开发工具 IntellJ IDE ...
- Google Breakpad 完全解析(一) —— Windows入门篇
原创文章,转载请标明出处:Soul Apogee (http://bigasp.com),谢谢. Google breakpad是一个非常实用的跨平台的崩溃转储和分析模块,他支持Windows,Lin ...
- Android 花钱 划动手指每天一元钱
花钱(英文ColorMoney)是由上海花动传媒开发的一款免费的应用程序,现支持Android操作系统.安装花钱app后,用户将获得全新的手机锁屏背景图,其中包含各种有趣.唯美的壁纸类图片,亦包含应用 ...
- Hibernate 注解@Column(nullable = false) 和 @Column(unique=true)
unique=true是指这个字段的值在这张表里不能重复,所有记录值都要唯一,就像主键那样; nullable=false是这个字段在保存时必需有值,不能还是null值就调用save去保存入库;
- minishift的本地代码构建
看文档说支持,但实际尝试了下,失败 发现仍然是找github中的代码 找了半天,发现是在目录下有.git的隐含目录,然后copy到其他目录下删除,然后再试,发现仍然失败. 日志看是指定的目录并没有传入 ...
- python升级导致yum命令无法使用的解决办法?
yum是依赖特定的python版本的,不同的linux系统需要的python版本不同. 查看yum的启动脚本:which is yum 头一行指定使用的python版本,这个必须是系统需要的,而不要使 ...