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

  • 相关阅读:
    spring mongodb查询
    spring mongodb分页,动态条件、字段查询
    js导航下拉菜单
    spring mongodb增删改查操作
    组件
    vue的基本指令
    远程连接MongoDB数据库
    webpack工具、Vue、react模块化
    layui
    anaconda使用,jupyter notebook的使用方法
  • 原文地址:https://www.cnblogs.com/lwh-note/p/9224226.html
Copyright © 2011-2022 走看看