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

推荐订阅源

L
LangChain Blog
月光博客
月光博客
S
SegmentFault 最新的问题
博客园 - 三生石上(FineUI控件)
Last Week in AI
Last Week in AI
J
Java Code Geeks
酷 壳 – CoolShell
酷 壳 – CoolShell
TaoSecurity Blog
TaoSecurity Blog
V
Visual Studio Blog
博客园 - 叶小钗
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Threat Research - Cisco Blogs
罗磊的独立博客
雷峰网
雷峰网
T
Tor Project blog
L
LINUX DO - 最新话题
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 司徒正美
Apple Machine Learning Research
Apple Machine Learning Research
Scott Helme
Scott Helme
Spread Privacy
Spread Privacy
C
CERT Recently Published Vulnerability Notes
腾讯CDC
Cloudbric
Cloudbric
WordPress大学
WordPress大学
Security Archives - TechRepublic
Security Archives - TechRepublic
V
V2EX
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
N
News and Events Feed by Topic
T
Troy Hunt's Blog
T
Threatpost
C
Check Point Blog
Vercel News
Vercel News
I
Intezer
Engineering at Meta
Engineering at Meta
C
Cybersecurity and Infrastructure Security Agency CISA
D
DataBreaches.Net
SecWiki News
SecWiki News
Help Net Security
Help Net Security
Microsoft Azure Blog
Microsoft Azure Blog
Google DeepMind News
Google DeepMind News
S
Secure Thoughts
T
The Blog of Author Tim Ferriss
The GitHub Blog
The GitHub Blog
Hacker News: Ask HN
Hacker News: Ask HN
AI
AI
N
News and Events Feed by Topic
阮一峰的网络日志
阮一峰的网络日志
B
Blog RSS Feed
Attack and Defense Labs
Attack and Defense Labs

披萨盒的赛博日志

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

披萨盒

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

个人主页