C++中使用Mongo执行count和distinct运算
来源:互联网 发布:艾瑞莉娅冰霜之刃淘宝 编辑:程序博客网 时间:2024/05/22 04:50
假设:服务端有Mongo数据库MyDB,其中有表MyTable,表中有字段"IP"和"Date"等,分别记录了访问本服务的客户端IP和访问时间,MyTable表访问权限的账号User,密码123456
(1)创建连接
mongo::DBClientConnection pConn = new mongo::DBClientConnection;string strErr;pConn->connect("127.0.0.1", strErr)pConn->auth("MyDB", "User", "123456", strErr);
(2)count运算
//统计该日期在区间DateStart和DateEnd内的记录数量
//"$gte"为Mongo的比较操作符>=,"$lte"为<=,"$gt"为>,"$lt"为<
int64 DateStart = 1315014772, DateEnd = 1317606772;unsigned int64 u64Count = pConn->count("MyTable", BSON("Date" << BSON("$gte" << DateStart << "$lte" << DateEnd)));
(3)distinct运算
//统计表中所有不同IP的数量
bo bobj; pConn->runCommand("MyDB", BSON("distinct" << "MyTabel" << "key" <<"IP", bobj)); vector<be> vecbe = obj.getField("values").Array(); size_t szIPCount = vecbe.size(); //查看具体IP vector<string> vecIP;for(size_t i=0; i<szIPCount; i++){vecIP.push_back(vecbe[i].String());}
//根据条件统计,在某时间段内访问服务的不同客户端IP的数量
pConn->runCommand("MyDB",BSON("distinct" << "MyTabel" << "key" << "IP" << "query" << BSON("Date" << BSON("$gte" << DateStart << "$lte" << DateEnd))), obj);
- C++中使用Mongo执行count和distinct运算
- C++中使用Mongo执行count和distinct运算
- SQL 中 Count 和Distinct的使用
- Hibernate中使用COUNT DISTINCT
- sql中count函数和distinct函数的配合使用
- oracle中distinct和count函数组合使用
- hibernat 中 count和distinct的联用
- hibernate 中的count和distinct同时使用
- Mysql中count(*),DISTINCT
- Kylin系列-在Apache Kylin中使用Count Distinct
- Mysql中count(*),DISTINCT的使用方法和效率研究
- Mysql中count(*),DISTINCT的使用方法和效率研究
- Mysql中count(*),DISTINCT的使用方法和效率研究
- Mysql中count(*),DISTINCT的使用方法和效率研究
- mysql 中 count()和distinct的一些杂想
- Mysql中count(*),DISTINCT的使用方法和效率研究
- Mysql中count(*),DISTINCT的使用方法和效率研究
- Mysql中count(*),DISTINCT的使用方法和效率研究
- CRF++模型文件格式分析
- Cocos2d-X精灵教程:第一部分
- Android Service---继承IntentService类
- 遍历lucene索引库
- UITextView 替换UILable显示链接文本
- C++中使用Mongo执行count和distinct运算
- 同步启用博客园-博客
- iOS 使用 md5加密
- Android Service---继承Service类
- Ramdisk, ramfs, tmpfs.
- Android Service---启动服务
- EXP-00056: 遇到 ORACLE 错误 6550
- Ubuntu 安装Jdk
- Android Service---终止服务