【Mongo】mongo聚合操作
1.mark 記個筆記
db.getCollection('redefine-collection').aggregate([
{ $match:{ 'stime': {'$gte':1526486400000, '$lt':1526572800000},'event_id': '0101001','uid':{'$type':2},'event_info.action': {'$in': [1, 4,6,9,16,18,21,23,24]} } },
{ $group:{ _id:{action:"$event_info.action",uid:"$uid"},total:{ $sum:1} } },
{ $group:{ _id:"$_id.action",total:{ $sum:"$total"} }}])
###分組後再分組,相當於子查詢
python mongo如何使用聚合函式:
http://api.mongodb.com/python/current/examples/aggregation.html
參考:
https://www.cnblogs.com/sweetchildomine/p/6430368.html
https://blog.csdn.net/xsdxs/article/details/52700189 ----- mongodb 中max、min、sum、avg等函式用法
-
db.getCollection('redefine-collection').aggregate([
-
{ $match:{ 'stime': {'$gte':1526486400000, '$lt':1526572800000},'event_id': '0101001','event_info.action': {'$in': [1, 4,6,9,16,18,21,23,24]} } },
-
{ $group:{ _id:"$event_info.action",total:{ $sum:"$page_source"} } } ####分組求和
-
])
-
-
db.getCollection('redefine-collection').aggregate([
-
{ $match:{ 'stime': {'$gte':1526486400000, '$lt':1526572800000},'event_id': '0101001','event_info.action': {'$in': [1, 4,6,9,16,18,21,23,24]} } },
-
{ $group:{ _id:"$event_info.action",total:{ $sum:1} } } ]) ###分組求count數
-
db.getCollection('redefine-collection').aggregate([
-
{ $match:{ 'stime': {'$gte':1526486400000, '$lt':1526572800000},'event_id': '0101001','event_info.action': {'$in': [1, 4,6,9,16,18,21,23,24]} } },
- { $group:{ _id:{action:"$event_info.action",uid:"$uid"},total:{ $sum:1} } } ]) ###多欄位分組求count數
db.getCollection('redefine-collection').aggregate([
{ $match:{ 'stime': {'$gte':1526486400000, '$lt':1526572800000},'event_id': '0101001','uid':{'$type':2},'event_info.action': {'$in': [1, 4,6,9,16,18,21,23,24]} } },
{ $group:{ _id:{action:"$event_info.action",uid:"$uid"},total:{ $sum:1} } },
{ $group:{ _id:"$_id.action",total:{ $sum:"$total"} }}])
###分組後再分組,相當於子查詢
####先分組,再過濾(group by having)
db.zipcodes.aggregate( [
{ $group: { _id: "$state", totalPop: { $sum: "$pop" } } },
{ $match: { totalPop: { $gte: 10*1000*1000 } } }
] )
http://api.mongodb.com/python/current/examples/aggregation.html
參考:
https://www.cnblogs.com/sweetchildomine/p/6430368.html
https://blog.csdn.net/xsdxs/article/details/52700189 ----- mongodb 中max、min、sum、avg等函式用法
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29096438/viewspace-2154727/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- mongo 聚合查詢Go
- mongo聚合框架aggregate使用Go框架
- mongo基本操作Go
- docker操作mongo+docker的常用操作+mongo與.netDockerGo
- go操作mongo CRUDGo
- 【Mongo】mongo配置檔案Go
- 【mongo】mongo 欄位型別互轉Go型別
- mongo GridFSBucketGo
- 【Mongo】shell命令列模式執行mongo命令Go命令列模式
- 【Mongo】Mongo讀寫分離的實現Go
- mongo 索引解析Go索引
- 管理索引mongo索引Go
- 安裝mongoGo
- 【Mongo】Mongodump 與 mongorestore對mongo進行備份恢復GoREST
- 【Mongo】mongo分片加複製集的備份恢復Go
- 【Mongo】mongo更新欄位為另一欄位的值Go
- mongo的‘模糊匹配’Go
- mongo副本集搭建Go
- mongo-go-driverGo
- mac 啟動mongoMacGo
- Prometheus監控mongoPrometheusGo
- Mongo連線分析Go
- mongo 小知識點Go
- 【Python】pymongo連結mongoPythonGo
- mongo基本命令(一)Go
- Mongo主從同步原理Go主從同步
- PostgreSQL 工具及mysql、mongoMySqlGo
- Mongo的bulkWrite介紹Go
- mongo資料備份Go
- logstach 8.6.2輸出到mongo 6Go
- spring data mongo @Field 失效問題SpringGo
- mongo 儲存過程詳解Go儲存過程
- 【Mongo】MongoDB WiredTiger引擎調優技巧MongoDB
- 領導不讓用mongo了Go
- usering mongotemplate bases on spring-Data-mongoGoSpring
- 自己製作redis 和mongo 映象RedisGo
- mongo3.2.7部署文件Go
- Homestead安裝mongo擴充套件Go套件