惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
News and Events Feed by Topic
D
DataBreaches.Net
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Recorded Future
Recorded Future
Y
Y Combinator Blog
C
Check Point Blog
Google DeepMind News
Google DeepMind News
M
MIT News - Artificial intelligence
小众软件
小众软件
F
Full Disclosure
S
SegmentFault 最新的问题
Blog — PlanetScale
Blog — PlanetScale
B
Blog RSS Feed
Martin Fowler
Martin Fowler
P
Proofpoint News Feed
博客园 - 司徒正美
量子位
The GitHub Blog
The GitHub Blog
T
The Blog of Author Tim Ferriss
T
Tenable Blog
P
Privacy International News Feed
T
The Exploit Database - CXSecurity.com
C
Cyber Attacks, Cyber Crime and Cyber Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
G
Google Developers Blog
P
Proofpoint News Feed
T
Threatpost
Know Your Adversary
Know Your Adversary
aimingoo的专栏
aimingoo的专栏
Latest news
Latest news
Security Latest
Security Latest
Cyberwarzone
Cyberwarzone
A
About on SuperTechFans
P
Palo Alto Networks Blog
Stack Overflow Blog
Stack Overflow Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Hacker News
The Hacker News
A
Arctic Wolf
AWS News Blog
AWS News Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
NISL@THU
NISL@THU
Last Week in AI
Last Week in AI
Hacker News - Newest:
Hacker News - Newest: "LLM"
Spread Privacy
Spread Privacy
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Application and Cybersecurity Blog
Application and Cybersecurity Blog
I
InfoQ
J
Java Code Geeks
H
Help Net Security

披萨盒的赛博日志

谈谈工作了半年的感受 使用策略模式重构复杂业务分支 像 systemd 一样管理 MacOS 后台常驻任务 以ORM看封装的边界 Git Merge VS Git Rebase: 如何优雅地合并分支? 修改Linux内核模块以支持WG OpenLDAP折腾日记 非特权模式容器 ssh 登录问题 在 Linux 开发环境中使用网络代理 白嫖 Aseprite 像素绘图软件 Python数据分析工具包-Numpy 解决 CLion 中文乱码问题 搭建 RLCraft 服务器 SpringBoot读取配置文件 Centos 配置 LNMP 环境 部署项目时遇到的坑 浅谈 xhr 请求跨域问题 JavaScript 学习笔记 Eclipse配置Web开发环境 Vue2 基本知识 Ribbon 简单使用 Nacos 简单使用 Spring Cloud Alibaba 环境搭建 什么是RSS?什么是Feed?它们有什么关系? Docker基本使用 TensorFlow启用GPU加速 如何进行内网穿透 Hello World! Git基本使用 Butterfly常用标签外挂
MongoDB 增删改查
披萨盒 · 2022-11-19 · via 披萨盒的赛博日志

数据库操作

查看所有数据库:show dbs;

image-20221105105938537

切换数据库:use xxx;

没有xxx时会自动创建

image-20221105105703199

新建集合(对应MySQL表):db.createCollection(‘xxx’);

image-20221105105823823

常用文档操作命令(增删改查)

1
2
3
4
5
6
db.collection.insertOne(
<document>,
{
writeConcern: <document>
}
)
1
2
3
4
5
6
db.collection.insertMany(
<document>,
{
writeConcern: <document>
}
)

image-20221105110341503

image-20221105110602314


1
2
3
4
5
6
db.emp.deleteMany({})    //删除所有文档
db.emp.deleteMany({name: 'pillage'}) //删除所有name=pillage的文档
db.emp.deleteMany({age: {$gt: 20}}) //删除所有age>20的文档
db.emp.deleteOne({name: 'pillage'}) //删除name=pillage的第一个文档

db.emp.findOneAndDelete({xxx}) //返回这个文档然后删除

image-20221105111347749


更新命令

1
2
3
4
5
6
7
8
db.collection.updateOne(query, update, options)
db.collection.updateMany(query, update, options)

query: 查询条件
update: 更新动作及新的内容
options: 可选,配置
upsert: boolean类型,默认false。设置为true后如果查询条件为空则插入
writeConcern: 一个写操作落到多少节点才算成功

更新操作符(update内容)

操作符 格式 描述
$set {$set: {field: value}} 指定一个键(字段)更新值,如果键不存在则创建
$unset {$unset: {field: 1}} 删除一个键
$inc {$inc: {field: number}} 对数值类型值进行加操作,number可以为负
$rename {$rename: {oldFiled: newField}} 修改键的名称
$push {$push: {field: value}} 将值添加到数组中,数组不存在则初始化
$pull {$pull: {field: value}} 从数组中删除指定元素
$addToSet {$addToSet: {field: value}} 添加元素到set集合(无序不重复)
$pop `{$pop: {field: 1 -1}}`

image-20221105114134991

image-20221105114147720

image-20221105114453806

image-20221105114922375

image-20221105120132480


1
2
3
4
db.collection.find(query, projection)

query: 可选。查询条件
projection: 可选。选择要查询哪些键的值

image-20221105121036012

image-20221105121104068

image-20221105121204868

image-20221105121526242

image-20221105121555540


版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-ND 4.0 许可协议。转载请注明来源 披萨盒的赛博日志


avatar

披萨盒

反正身体这么好,今天继续笑下去吧

个人主页