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

推荐订阅源

WordPress大学
WordPress大学
Application and Cybersecurity Blog
Application and Cybersecurity Blog
G
GRAHAM CLULEY
P
Privacy International News Feed
L
LINUX DO - 热门话题
C
Cisco Blogs
T
Tor Project blog
AWS News Blog
AWS News Blog
K
Kaspersky official blog
C
Cybersecurity and Infrastructure Security Agency CISA
Cyberwarzone
Cyberwarzone
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
CERT Recently Published Vulnerability Notes
P
Proofpoint News Feed
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
L
Lohrmann on Cybersecurity
C
CXSECURITY Database RSS Feed - CXSecurity.com
Project Zero
Project Zero
Attack and Defense Labs
Attack and Defense Labs
Latest news
Latest news
The Last Watchdog
The Last Watchdog
Apple Machine Learning Research
Apple Machine Learning Research
Simon Willison's Weblog
Simon Willison's Weblog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Cloudbric
Cloudbric
Last Week in AI
Last Week in AI
S
Security Affairs
Google DeepMind News
Google DeepMind News
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
有赞技术团队
有赞技术团队
V
Visual Studio Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
小众软件
小众软件
P
Palo Alto Networks Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
S
Security @ Cisco Blogs
V
V2EX
S
Secure Thoughts
人人都是产品经理
人人都是产品经理
月光博客
月光博客
博客园_首页
T
Troy Hunt's Blog
爱范儿
爱范儿
N
News and Events Feed by Topic
Hugging Face - Blog
Hugging Face - Blog
雷峰网
雷峰网
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
P
Privacy & Cybersecurity Law Blog
V
Vulnerabilities – Threatpost

披萨盒的赛博日志

谈谈工作了半年的感受 使用策略模式重构复杂业务分支 像 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

披萨盒

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

个人主页