和小青GPT助理聊天吧

小青是一位基于大语言预训练模型的超级智能AI,熟悉轻易云产品并能为您提供多种数据集成方案和技术支持。您在使用轻易云产品时遇到问题或有关技术咨询,小青都将为您提供专业、即时、高效的帮助和建议。与小青智能对话,您可享受同人类互动一样的使用体验,全面了解最新产品更新、功能特性及相关技术资讯,进一步提升您在数据集成领域的实力。小青是您友好、智能、便捷的助手,与她互动让您的数据集成之路轻松愉快。
轻易云自训练大语言模型小青助理
扫码关注公众号即可开始聊天

MongoDB写法介绍

简单介绍

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	无

还没写完

热门文章

道一云与畅捷通T+对接集成获取报销信息列表=>凭证创建(报销装卸费(天水))

2023-01-19 10:19:43

小满OKKICRM与金蝶云星空对接集成客户列表查询&客户新增(小满客户对接金蝶客户-P)

2023-01-19 10:17:47

畅捷通T+和旺店通·企业奇门单据接口对接

2023-01-19 10:16:42

金蝶云星空与轻易云集成平台对接集成仓库查询&写入空操作

2023-01-19 10:14:34

各平台API授权获取方式总览

2023-01-19 03:42:49