MongoDB查询语句

--查询近三个月的客户使用量  aggregate:使用聚合  match:过滤  group分组   
-- mysql中
select org_code as 近三个月使用商户 from pomelo_backend_production.landi_configurations
where created_at between '2018-03-22 00:00:00' and '2018-06-22 00:00:00'
GROUP BY org_code;

--mongodb中  db.表名.aggregate([])
db.tuan_activities.aggregate([
{$match : { created_at : { $gt : ISODate("2018-03-22T00:00:00.000Z"), $lte : ISODate("2018-06-31T00:00:00.000Z") } } },
{$group : {_id : "$org_code", num_tutorial : {$sum : 1}}}
])

-- 查询近三个月所有数据
-- mysql中
select count(*) as 近三个月数据 from pomelo_backend_production.landi_configurations
where created_at between '2018-03-22 00:00:00' and '2018-06-22 00:00:00';

--mongodb中
db.getCollection('tuan_activities').find({ "created_at" : { "$gte" :ISODate("2018-03-22T00:00:00.000Z"),
    "$lt" : ISODate("2018-06-31T00:00:00.000Z")}}).sort({created_at:-1})

-- 分组
db.getCollection('tuan_activities').aggregate([
{
    $group:{
            _id: '$org_code',
             num_tutorial : {$sum : 1}
       }
}
]
)

最新文章

  1. AnyCAD .Net SDK 用户手册 v2013.1
  2. uva 11054 wine trading in gergovia (归纳【好吧这是我自己起的名字】)——yhx
  3. linux samba.tar.gz安装和配置
  4. 定义 ICache 接口,以及实现默认的 ASP.NET 缓存机制
  5. Memo 的当前行、当前列与当前字符
  6. 神奇的版本库—————GIT
  7. mybatis 详解------动态SQL
  8. sql的转义字符单引号
  9. lua内存监测和回收
  10. Tyrion 中文文档(含示例源码)
  11. Selenium Web 自动化 - 项目实战(一)
  12. python day 06 作业
  13. BZOJ 3131 [SDOI2013]淘金 - 数位DP
  14. 学习 HTML+CSS 的书籍推荐
  15. powerdesigner 生成数据库脚本
  16. 万恶之源 - Python函数进阶
  17. 【英宝通Unity4.0公开课学习 】(三)脚本使用
  18. Java中的内存划分
  19. The adidas NMD Singapore is one of the brands top selling
  20. Python正则表达式之 - ?: / ?= / ?!

热门文章

  1. string 驻留机制
  2. redis和mongodb面试题(一)
  3. redis弱密码漏洞利用
  4. 010-SaltStack及SaltStack Web UI安装部署
  5. PyCharm上unittest 测试用例两种执行方式
  6. java8学习之内部迭代与外部迭代本质剖析及流本源分析
  7. Django-多对多建表与Form表单
  8. 基于角色权限管理:rbac具体代码实现
  9. Socket的通信机制?
  10. Java验证身份证是否合法