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

推荐订阅源

SecWiki News
SecWiki News
I
InfoQ
The Cloudflare Blog
人人都是产品经理
人人都是产品经理
博客园 - Franky
T
Tailwind CSS Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
量子位
博客园_首页
罗磊的独立博客
V
V2EX
李成银的技术随笔
大猫的无限游戏
大猫的无限游戏
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
True Tiger Recordings
Vercel News
Vercel News
Cyberwarzone
Cyberwarzone
Cisco Talos Blog
Cisco Talos Blog
F
Fox-IT International blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
M
Microsoft Research Blog - Microsoft Research
Know Your Adversary
Know Your Adversary
爱范儿
爱范儿
The Register - Security
The Register - Security
G
Google Developers Blog
The Hacker News
The Hacker News
Malwarebytes
Malwarebytes
S
Securelist
博客园 - 三生石上(FineUI控件)
Jina AI
Jina AI
T
Threat Research - Cisco Blogs
T
The Exploit Database - CXSecurity.com
S
SegmentFault 最新的问题
博客园 - 叶小钗
F
Fortinet All Blogs
Apple Machine Learning Research
Apple Machine Learning Research
宝玉的分享
宝玉的分享
博客园 - 聂微东
T
Threatpost
博客园 - 【当耐特】
D
Docker
P
Privacy & Cybersecurity Law Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
G
GRAHAM CLULEY
V
Visual Studio Blog
C
Cisco Blogs
IT之家
IT之家
S
Security Archives - TechRepublic
Latest news
Latest news
阮一峰的网络日志
阮一峰的网络日志

披萨盒的赛博日志

使用策略模式重构复杂业务分支 像 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

披萨盒

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

个人主页