当前位置:网站首页>MongoDB的一些基础用法
MongoDB的一些基础用法
2022-06-25 22:12:00 【大魔王的日常Log】
创建MongoDB容器
docker run di --name=tianxingwen_mongodb -p 27017:27017 mongo
远程登录
mongo 192.168.53.132
创建数据库
use spitdb
增删改查语法
查询
语法:
db.集合名称.find()
db.spit.find()
根据id查询某条数据
db.spit.find({"_id":“1”})
db.spit.findOne({"_id":“1”})
查询前几条数据
db.spit.find().limit(3)
新增
插入数据
语法:
db.集合名称.insert(数据);
db.spit.insert({content:“好冷啊”,visits:10})
修改
语法:
db.集合名称.update(条件,修改后的数据)
db.spit.update({_id:“1”},{visits:NumberInt(1000)})
注意上面这条命令执行后id为1的其他字段都会自动删掉
解决办法:
db.spit.update({_id:“2”},{$set:{visits:NumberInt(2000)}})
删除
语法:
db.集合名称.remove(条件)
删除全部
db.spit.remove({})
根据条件删除 删除visits:1000的这条数据
db.spit.remove({visits:1000})
统计
统计所有
db.spit.count()
根据指定条件统计
db.spit.count({userid:“1013”})
模糊查询
查询content字段包含java的所有文档
db.spit.find({content:/java/})
查询content以java开头的
db.spit.find({content:/^java/})
大于小于
语法:
db.集合名称.find({ “field” : { $gt: value }}) // 大于: field > value db.集合名称.find({ “field” : { $lt: value }}) // 小于: field < value db.集合名称.find({ “field” : { $gte: value }}) // 大于等于: field >= value
db.集合名称.find({ “field” : { $lte: value }}) // 小于等于: field <= value
db.集合名称.find({ “field” : { $ne: value }}) // 不等于: field != value
查询id>1的数据
db.spit.find({"_id":{$gt:“1”}})
包含与不包含
查询userid字段包含1013,1014的文档
db.spit.find({userid:{$in:[“1013”,“1014”]}})
查询userid字段不包含1013,1014的文档
db.spit.find({userid:{$nin:[“1013”,“1014”]}})
条件连接
语法格式
$and:[ { },{ },{ } ]
查询集合中visits大于等于1000 并且小于2000的文
db.spit.find({ KaTeX parse error: Expected '}', got 'EOF' at end of input: and:[ {visits:{ gte:1000}} ,{visits:{$lt:2000} }]})
如果两个以上条件之间是或者的关系,我们使用 操作符进行关联,与前面and的使用 方式相同
KaTeX parse error: Expected '}', got 'EOF' at end of input: …*db.spit.find({ or:[ {userid:“1013”} ,{visits:{$lt:2000} }]})
二级标题
对某列值在原有值的基础上进行增加或减少,可以使用KaTeX parse error: Expected '}', got 'EOF' at end of input: …ate({_id:"2"},{ inc:{visits:NumberInt(1)}} )**
边栏推荐
- 14.1.1 promethues monitoring, four data types metrics, pushgateway
- Read CSV file data in tensorflow
- 10.2.3、Kylin_ The dimension is required for kylin
- 《网络是怎么样连接的》读书笔记 - 集线器、路由器和路由器(三)
- Unable to start debugging. Unexpected GDB output from command “-environment -cd xxx“ No such file or
- 如何配置SQL Server 2008管理器_过路老熊_新浪博客
- Search rotation array ii[Abstract dichotomy exercise]
- 电路板去板边—V-Cut分板机注意事项
- js实现输入开始时间和结束时间,输出其中包含多少个季,并且把对应年月打印出来
- Using swiper to realize the rotation chart
猜你喜欢

Literature research (III): overview of data-driven building energy consumption prediction models

关于运行scrapy项目时提示 ModuleNotFoundError: No module named 'pymongo‘的解决方案
![Search rotation array ii[Abstract dichotomy exercise]](/img/db/3ea01cf1ad8446a7007891ef1d8e7f.png)
Search rotation array ii[Abstract dichotomy exercise]

关于scrapy爬虫时,由spider文件将item传递到管道的方法注意事项

ValueError: color kwarg must have one color per data set. 9 data sets and 1 colors were provided

Literature research (I): hourly energy consumption prediction of office buildings based on integrated learning and energy consumption pattern classification

WINCC与STEP7的仿真连接_过路老熊_新浪博客

Unsigned and signed vernacular

Literature research (II): quantitative evaluation of building energy efficiency performance based on short-term energy prediction

STEP7主站与远程I/O组网_过路老熊_新浪博客
随机推荐
懒人教你用猕猴桃一月饱减16斤_过路老熊_新浪博客
About Simple Data Visualization
记录一些cf的题
Transformation of communication protocol between Siemens S7-200PLC and Danfoss inverter_ Old bear passing by_ Sina blog
Rocket之消息存储
Lazy people teach you to use kiwi fruit to lose 16 kg in a month_ Old bear passing by_ Sina blog
js实现输入开始时间和结束时间,输出其中包含多少个季,并且把对应年月打印出来
10.2.3、Kylin_ The dimension is required for kylin
Final and static
Implement const in Es5
Alipay payment interface sandbox environment test and integration into an SSM e-commerce project
寻找翻转数组的最小值[抽象二分]
10.4.1、数据中台
Literature research (I): hourly energy consumption prediction of office buildings based on integrated learning and energy consumption pattern classification
(Reprint) visual explanation of processes and threads
ValueError: color kwarg must have one color per data set. 9 data sets and 1 colors were provided解决
对象数组去重
10.3.1、FineBI_finebi的安装
Idea common shortcut keys
我的博客今天2岁167天了,我领取了先锋博主徽章_过路老熊_新浪博客