MongoDB是一个基于分布式文件存储的数据库
由C++语言编写,旨在为WEB应用提供可扩展的高性能数据存储解决方案。
MongoDB是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的。
它支持的数据结构非常松散,是类似json的bson格式,因此可以存储比较复杂的数据类型。
Mongo最大的特点是它支持的查询语言非常强大,其语法有点类似于面向对象的查询语言,几乎可以实现类似关系数据库单表查询的绝大部分功能,而且还支持对数据建立索引
查询所有
MongoDB db.getCollection('user').find({});
MySQL select * from user;
查询条件:=
MongoDB db.getCollection('user').find({"uclass":"A"});
MySQL select * from user where uclass = 'A';
```
查询条件:like
```json
MongoDB db.getCollection('user').find({"name":/Ba/});
MySQL select * from user where name like '%Ba%';
查询条件:distinct
MongoDB db.getCollection('user').distinct("name");
MySQL select distinct uclass from user u;
查询条件:$gt
MongoDB db.getCollection('user').find({"age":{$gt:16}}); greater than >
MySQL select * from user where age >16;
查询条件:$gte
MongoDB db.getCollection('user').find({"age":{$gte:16}}); gt equal >=
MySQL select * from user where age >= 16;
```
查询条件:$lt
```josn
MongoDB db.getCollection('user').find({"age":{$lt:16}}); less than <
MySQL select * from user where age < 16;
查询条件:$lte
MongoDB db.getCollection('user').find({"age":{$lte:16}}); lt equal <=
MySQL select * from user where age <= 16;
查询条件:$ne
MongoDB db.getCollection('user').find({"age":{$ne:16}}); not equal !=
MySQL select * from user where age != 16;
```
查询条件:$eq
```josn
MongoDB db.getCollection('user').find({"age":{$eq:16}});等效于:db.getCollection('user').find({"age":16});
MySQL select * from user where age = 16;
查询条件:in
MongoDB db.getCollection('user').find({"uclass":{$in:['A', 'B']}});
MySQL select * from user where uclass in ('A', 'B');
```
查询条件:and
```josn
MongoDB db.getCollection('user').find({"uclass":"B", "age":{$gt:16}});
MySQL select * from user where uclass = 'B' and age > 16;
```
查询条件:or
```josn
MongoDB db.getCollection('user').find({$or:[{"uclass":"A"},{"class":"B"}]});
MySQL select * from user where uclass = 'A' or uclass = 'B';
查询条件:时间
MongoDB db.getCollection('user').find({"birthday":{$gt: new Date("2008-08-14T06:24:40.110Z"), $lt: new Date("2015-08-14T06:14:40.089Z")}});
MySQL select * from user where birthday > '2008-08-14 06:24:40' and birthday < '2015-08-14 06:14:40';
```
查询条数:count
```josn
MongoDB db.getCollection('user').find({"uclass":"A"}).count();
MySQL select count(1) from user where uclass = 'A';
查询条件:sort升序
MongoDB db.getCollection('user').find({}).sort({"age":1});
MySQL select * from user order by age asc;
查询条件:sort降序
MongoDB db.getCollection('user').find({}).sort({"age":-1});
MySQL select * from user order by age desc;
聚合查询:count单列
MongoDB db.getCollection('user').aggregate([{$group:{_id:"$uclass",num:{$sum:1}}}]);
MySQL select uclass, count(1) as num from user group by uclass;
聚合查询:count多列
MongoDB db.getCollection('user').aggregate([{$group:{_id:{uclass:"$uclass", age:"$age"},num:{$sum:1}}}]);
MySQL select uclass, age, count(1) as num from user group by uclass, age;
```
分页查询:limit n
```josn
MongoDB db.getCollection('user').find({}).limit(5); 查询前n条
MySQL select * from user limit 5;
分页查询:limit m,n
MongoDB db.getCollection('user').find({}).limit(5).skip(5); 查询n条,从第m条开始
MySQL select * from user limit 5,5;
查询指定字段
MongoDB db.getCollection('user').find({}, {userId:1, name:1}); 第一个{}为查询条件
MySQL select userId, name from user;
```
排查指定字段
```josn
MongoDB db.getCollection('user').find({}, {dataStatus:0, _id:0}); 第一个{}为查询条件
MySQL 无
还没写完
2021-07-11 01:02:01 | |
2023-12-14 10:37:52 | |
2021-09-28 08:43:23 | |
2023-03-13 10:05:30 | |
2024-02-12 20:23:49 | |
2021-11-13 17:04:54 | |
2024-02-06 18:50:13 | |
2022-11-01 04:08:45 | |
2024-03-02 11:20:06 | |
2022-01-16 19:19:38 | |
2024-11-15 22:18:03 | |
2024-11-28 19:31:55 | |
2024-10-27 08:18:52 | |
2024-12-11 05:16:32 | |
2024-10-23 11:27:13 | |
2024-10-31 11:27:27 | |
2025-01-27 11:27:19 | |
2025-02-14 11:27:52 | |
2025-02-22 11:26:28 | |
2025-02-28 11:28:11 | |
2024-03-06 09:31:16 | |
2024-03-06 09:28:11 | |
2024-03-06 09:25:03 | |
2024-03-05 07:36:57 | |
2024-03-04 10:02:59 |
胡秀丛 15813570600
数据集成顾问 项目总监 她以卓越的数据集成专长,精通ERP、MES系统,以及数据中台的构建与优化。通过创新的一站式解决方案,她助力企业实现数据的无缝对接,提升业务流程效率,确保信息流通无障碍,为企业的数字化转型提供强有力的支持。
何海波 18175716035
数据集成顾问 轻易云的技术专家,拥有丰富的数据集成规划经验。他能够为客户提供专业、全面的数据集成规划方案,熟练掌握多种集成技术和工具,帮助企业在数据集成领域得到长远发展。
卢剑航 13760755942
数据集成专家 拥有十多年丰富的经验,擅长ERP、MES、数据中台、营销云中台等集成。他能够根据客户需求,为其提供一站式集成解决方案,帮助企业快速实现各类系统数据集成服务。
黄宏棵 13286997615
数据集成顾问 资深系统集成顾问,专长于ERP、电商OMS、钉钉及CRM系统。他能提供高效的集成方案,优化企业运营流程,提升业务效率和决策智能化。