当前位置:网站首页>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)}} )**
边栏推荐
- Reading notes on how to connect the network - hubs, routers and routers (III)
- 手工制作 pl-2303hx 的USB轉TTL電平串口的電路_過路老熊_新浪博客
- 网络连接验证
- SMT贴片加工PCBA板清洗注意事项
- 记录一些cf的题
- 10.4.1 données intermédiaires
- ValueError: color kwarg must have one color per data set. 9 data sets and 1 colors were provided
- 11.1.2、flink概述_Wordcount案例
- Shredding Company poj 1416
- 在step7中实现模拟量数值与工程量数值之间的转换_过路老熊_新浪博客
猜你喜欢

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

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

《网络是怎么样连接的》读书笔记 - 集线器、路由器和路由器(三)

Redis之内存淘汰机制

Establishment of multiple background blocks in botu software_ Old bear passing by_ Sina blog

Summary of c++ references and pointers

Studio5k V28 installation and cracking_ Old bear passing by_ Sina blog

Linking MySQL database with visual studio2015 under win10

Unsigned and signed vernacular

手工制作 pl-2303hx 的USB轉TTL電平串口的電路_過路老熊_新浪博客
随机推荐
Linking MySQL database with visual studio2015 under win10
ValueError: color kwarg must have one color per data set. 9 data sets and 1 colors were provided解决
我的博客今天2岁167天了,我领取了先锋博主徽章_过路老熊_新浪博客
js实现输入开始时间和结束时间,输出其中包含多少个季,并且把对应年月打印出来
手工制作 pl-2303hx 的USB转TTL电平串口的电路_过路老熊_新浪博客
给定参数n,从1到n会有n个整数1,2,3,...,n,这n个数组共有n!种排列,按照大小顺序升序排列出所有列的情况,并一一标记,给定n和k,返回第k个值
SMT贴片加工pcba立碑现象的原因和解决方法
寻找翻转数组的最小值[抽象二分]
Shredding Company poj 1416
兆欧表电压档位选择_过路老熊_新浪博客
Literature research (I): hourly energy consumption prediction of office buildings based on integrated learning and energy consumption pattern classification
STEP7 master station and remote i/o networking_ Old bear passing by_ Sina blog
Simulation connection between WinCC and STEP7_ Old bear passing by_ Sina blog
Shredding Company poj 1416
Backup restore of xtrabackup
Talk about the copy on write mechanism of PHP variables or parameters
虚析构和纯虚析构及C ++实现
The role of iomanip header file in actual combat
Smt贴片加工出现元件立碑的解决方法
使用npm创建并发布包时遇到的常见问题