当前位置:网站首页>MongoDB-CUD without R
MongoDB-CUD without R
2022-07-30 07:43:00 【HDLaZy】
1:基本语法
显示数据库
show dbs;
创建数据库/切换数据库
#It will not be displayed if the database is empty
use 数据名;
删除数据库
db.dropDatabase();
Displays collections in the database
show collections;
创建集合
db.createCollection('集合名');
删除集合
db.集合名.drop();
2:插入数据
插入单条数据
如果没有_id字段
will generate one by default_id字段
_id
的value为唯一键,不能重复
db.集合名.insertOne(
{
"_id":1,
"name":"HDLaZy"
}
)
插入多条数据
Insert as an array
db.集合名.insertMany([
{
"name":"唐僧","age":"11"},
{
"name":"孙悟空","age":"1000","武器":"如意金箍棒"},
{
"name":"八戒","住址":"高老庄"}
])
结果:
Insert multiple or single data
db.集合名.insert()
save方法
save方法使用时,If the document has相同的_id
,Then go directly to the document覆盖
,如果
没有相同的_id,那么就新增
一条文档
db.集合名.save(
{
"_id":1,"name":"沙和尚"}
)
3:修改数据
覆盖修改
Overwrite the old data with the new data
db.集合名.update(
#参数1,类似于MySql的where
{
"name":"孙悟空"},
#参数2,类似于MySql的set XXX=YYY
{
"name":"弼马温","住址":"花果山"},
#参数3,是否批量修改,默认为falseThat is, no batch modification is performed
{multi:false}
)
结果:
set修改器
setManipulate fields that do not exist,则会自动创建
db.集合名.update(
{
"name":"弼马温"},
{
'$set':{
"name":"齐天大圣","坐骑":"筋斗云"}}
)
结果:unset修改器
使用unsetto delete a field,删除字段时,只在乎key而不在乎value
db.集合名.update(
{
"name":"齐天大圣"},
{
'$unset':{
'坐骑':1}}
)
结果:
4:删除数据
删除文档
db.集合名.remove(
#The delete condition is similar toMySql的where
{
'_id':ObjectId("62d6c7da3cde2139380017c3")}
)
删除所有文档
db.集合名.remove({})
边栏推荐
- 多线程进阶(锁策略,自旋+CAS,Synchronized,JUC,信号量)
- 牛客:删除公共字符
- 图计算101:图计算的类型、语言与系统
- PC DBCO-PEG3-Biotin|PC-生物素-PEG3-DBCO可用于使用无铜点击化学
- Shortcut keys commonly used in the use of Word
- 测试开发工程师成长日记018 - 测试面试必备题记录(持续更新)
- 如何使用xilinx的FFT ip
- ParseException line 8:13 mismatched input ‘(‘ expecting ) near ‘int‘ in create table statement
- com.alibaba.datax.common.exception.DataXException: Code:[ESWriter-03]
- Vineyard: An open source distributed in-memory data management framework
猜你喜欢
Biotin-PEG4-DADPS-Picolyl-azide(CAS:2599839-59-3)生物素试剂
网络协议01 - 基础概念
元宇宙与图扑国风的碰撞,科技与文化的虚实融合
Dachang's annual salary of 50w+ recruits test engineers with test platform development capabilities
Vineyard: An open source distributed in-memory data management framework
图计算在网络安全分析中的应用
基于精灵(Sprite)管道烟雾流动效果
Install MySQL under Linux (centos7)
Selenium02
Vineyard: 开源分布式内存数据管理框架
随机推荐
flask项目快速搭建部署gunicorn+supervisor
04-加壳和脱壳
测试开发工程师成长日记009 - 环境排排站:开发环境、测试环境、生产环境、UAT环境、仿真环境
【无标题】
多线程基础(多线程内存,安全,通信,线程池和阻塞队列)
测试开发工程师成长日记016 - 关于提测的那些事
prometheus监控nacos
From installation to compilation: 10 minutes to teach you to use and develop GraphScope locally
网络协议03 - 路由和NAT
How to create a shortcut without the "shortcut" suffix?
Graph Computing 101: Types, Languages, and Systems of Graph Computing
作为测试leader,考察求职者的几个方面
含 3 个单元 PEG 的 ADC linker的PC DBCO-PEG3-Biotin
Shortcut keys commonly used in the use of Word
Biotin-C6-amine_N-生物素基-1,6-己二胺_CAS:65953-56-2_100mg
图扑软件数字孪生民航飞联网,构建智慧民航新业态
GCD timer
ParseException line 8:13 mismatched input ‘(‘ expecting ) near ‘int‘ in create table statement
Deploy GraphScope with Helm
软件测试_01