zoukankan      html  css  js  c++  java
  • MongoDB简单查询语句<平时使用语录,持续更新>

    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}
           }
    }
    ]
    )

  • 相关阅读:
    MFC中的菜单(Menu)
    MFC中获取系统无任何操作的时间
    MFC中使用快捷键Accelerator
    Git的安装和使用
    给pdf添加目录
    练习题2
    练习题1
    主键和外键
    数据库知识点
    多表查询
  • 原文地址:https://www.cnblogs.com/lwh-note/p/9224226.html
Copyright © 2011-2022 走看看