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

推荐订阅源

S
Schneier on Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Know Your Adversary
Know Your Adversary
G
GRAHAM CLULEY
V
Vulnerabilities – Threatpost
P
Palo Alto Networks Blog
Security Latest
Security Latest
P
Privacy & Cybersecurity Law Blog
Simon Willison's Weblog
Simon Willison's Weblog
A
Arctic Wolf
T
Tor Project blog
T
Threatpost
NISL@THU
NISL@THU
I
InfoQ
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Apple Machine Learning Research
Apple Machine Learning Research
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
aimingoo的专栏
aimingoo的专栏
Microsoft Azure Blog
Microsoft Azure Blog
WordPress大学
WordPress大学
K
Kaspersky official blog
W
WeLiveSecurity
L
LINUX DO - 热门话题
小众软件
小众软件
Recorded Future
Recorded Future
B
Blog RSS Feed
H
Help Net Security
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
IT之家
IT之家
L
Lohrmann on Cybersecurity
Last Week in AI
Last Week in AI
Stack Overflow Blog
Stack Overflow Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
阮一峰的网络日志
阮一峰的网络日志
V
Visual Studio Blog
Blog — PlanetScale
Blog — PlanetScale
雷峰网
雷峰网
爱范儿
爱范儿
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threat Research - Cisco Blogs
C
Cyber Attacks, Cyber Crime and Cyber Security
H
Hacker News: Front Page
博客园 - 三生石上(FineUI控件)
N
Netflix TechBlog - Medium
P
Proofpoint News Feed
有赞技术团队
有赞技术团队
N
News and Events Feed by Topic
云风的 BLOG
云风的 BLOG
Scott Helme
Scott Helme
V2EX - 技术
V2EX - 技术

披萨盒的赛博日志

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

披萨盒

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

个人主页