当前位置:网站首页>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)}} )**
边栏推荐
- P3052 [USACO12MAR]Cows in a Skyscraper G
- Network protocol: detailed explanation of redis protocol
- (Reprint) visual explanation of processes and threads
- Talk about singleton mode!
- Installation of third-party library iGraph for social network visualization
- 兆欧表电压档位选择_过路老熊_新浪博客
- 如何配置SQL Server 2008管理器_过路老熊_新浪博客
- Redis之跳跃表
- 搜索旋转数组II[抽象二分练习]
- Redis之内存淘汰机制
猜你喜欢

Circuit de fabrication manuelle d'un port série de niveau USB à TTL pour PL - 2303hx Old bear passing Sina blog

11.1.1、flink概述_flink概述

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

兆欧表电压档位选择_过路老熊_新浪博客
![Search rotation array ii[Abstract dichotomy exercise]](/img/db/3ea01cf1ad8446a7007891ef1d8e7f.png)
Search rotation array ii[Abstract dichotomy exercise]

How to configure SQL Server 2008 Manager_ Old bear passing by_ Sina blog

MySQL version upgrade + data migration

STEP7 master station and remote i/o networking_ Old bear passing by_ Sina blog
![寻找翻转数组的最小值[抽象二分]](/img/b9/1e0c6196e6dc51ae2c48f6c5e83289.png)
寻找翻转数组的最小值[抽象二分]

Simulation connection between WinCC and STEP7_ Old bear passing by_ Sina blog
随机推荐
STEP7 master station and remote i/o networking_ Old bear passing by_ Sina blog
About Simple Data Visualization
手工制作 pl-2303hx 的USB转TTL电平串口的电路_过路老熊_新浪博客
Smt贴片加工出现元件立碑的解决方法
Unable to start debugging. Unexpected GDB output from command “-environment -cd xxx“ No such file or
2021-04-28
Redis之哨兵
Establishment of multiple background blocks in botu software_ Old bear passing by_ Sina blog
Prototype chain test questions in JS --foo and getname
keil编译运行错误,缺少error:#5:#includecore_cm3.h_过路老熊_新浪博客
文献调研(一):基于集成学习和能耗模式分类的办公楼小时能耗预测
SSM integrated learning notes (mainly ideas)
14.1.1 promethues monitoring, four data types metrics, pushgateway
How postman tests interfaces that require login
Notes on the method of passing items from the spider file to the pipeline in the case of a scratch crawler
(转载)进程和线程的形象解释
关于二分和双指针的使用
如何配置SQL Server 2008管理器_过路老熊_新浪博客
详解synchronize关键字
mysql 主从复制