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