ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

mongodb第一篇:基本概念

2022-09-16 20:00:29  阅读:318  来源: 互联网

标签:collectionName name 第一篇 mongodb age db find 基本概念 select


mongodb是一个文档数据库。

 

https://blog.csdn.net/qq_44300280/article/details/123936134

 

java客户端使用:https://article.itxueyuan.com/MRjEAp

go客户端使用:

 

命令行客户端命令:

查询:

db.$collectionName.find():查全表数据

db.$collectionName.distinct("name"):等价于select distinct name from t

db.$collectionName.find({"name":"张三"}):等价于select * from t where name = '张三'

db.$collectionName.find({"age":18}):等价于select * from t where age = 18

db.$collectionName.find({"age":{$gt:18}}):等价于select * from t where age >18

db.$collectionName.find({"age":{$gte:18}}):等价于select * from t where age >= 18

db.$collectionName.find({"age":{$lt:60}}):等价于select * from t where age < 60

db.$collectionName.find({"age":{$lte:60}}):等价于select * from t where age <= 60

db.$collectionName.find({"age":{$gt:18,$lt:60}}):等价于select * from t where age > 18 and age < 60

db.$collectionName.find({}, {"name":1, "age":1}):等价于select name, age from t

db.$collectionName.find({"age":{$gt:18}}, {"name":1}):等价于select name from t where age > 18

db.$collectionName.find({}, {"name":0}):查询name之外的全部列

db.$collectionName.find().sort({"age":1}):等价于select * from t order by age

db.$collectionName.find().sort({"age":-1}):等价于select * from t order by age desc

db.$collectionName.find({"name":"张三", "age": 55}):等价于select * from t where name = '张三' and age = 55

db.$collectionName.find().limit(5):等价于select * from t limit 5

db.$collectionName.find().skip(10):跳过前10条数据

db.$collectionName.find().limit(10).skip(5):等价于select * from t limit 5, 10,即跳过前5条数据,查询10条数据

db.$collectionName.find({$or:[{"age":20}, {"age":30}]}):等价于select * from t where age = 20 or age = 30

db.$collectionName.findOne():等价于select * from t limit 1

db.$collectionName.find().count():等价于select count(1) from t

 

新增:

db.$collectionName.save({"name":"李四", "age":25}):等价于insert into t (name, age) values ('李四', 25)

 

修改:

db.$collectionName.update({"name":"李四"}, {$set:{"age":60}}, false, true):等价于update t set age = 60 where name = '李四',第一个false表示的是,第二个true表示的是

db.$collectionName.update({"name":"李四"}, {$inc:{"age":10}}, false, true):等价于update t set age = age + 10 where name = '李四'

db.$collectionName.update({"name":"李四"}, {$set:{"name":"张三"}, $inc:{"age":10}}, false, true):等价于update t set name = '张三', age = age + 10 where name = '李四'

 

删除:

db.$collectionName.remove({"name":"李四"}):等价于delete * from t where name = '李四'

 

清空表数据:

db.$collectionName.drop():等价于truncate table t

 

标签:collectionName,name,第一篇,mongodb,age,db,find,基本概念,select
来源: https://www.cnblogs.com/koushr/p/16698312.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有