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

  • 相关阅读:
    PHP设置时区
    MySQL基本数据操作
    MySQL更改字段名
    MySQL修改数据表
    MySQL数据表的修改
    MySQL表级约束和列级约束
    MySQL外键约束的参照操作
    MySQL约束
    MySQL默认约束DEFAULT
    [Caffe]:关于*** Aborted at 1479432790 (unix time) try "date -d @1479432790" 错误的另一种原因
  • 原文地址:https://www.cnblogs.com/lwh-note/p/9224226.html
Copyright © 2011-2022 走看看