[MongoDB] Remove, update, create document
MongoDB create update Document remove
2023-09-14 09:00:54 时间
Remove:
remove the wand with the name
of "Doom Bringer"
from our wands
collection.
db.wands.remove({name: "Doom Bringer"})
>> WriteResult({'ngRemoved': 1})
When we removed the "Doom Bringer"
wand, we noticed that it had a power of "Death"
, and we don't want any wands like that in our database. To be safe, let's remove any wands containing that in their powers
.
db.wands.remove({name: "Doom Bringer", powers: "Death"})
Update:
Write the command to update the wand with a name
of "Devotion Shift"
and set the price
to 5.99
.
db.wands.update({name: "Devotion Shift"},{"$set": {price: 5.99}});
Update all the document: "multi"
Increase level_required by 2, apply to all the documents match {powers: "Fire"}:
db.wands.update( {powers: "Fire"}, {"$inc":{level_required: 2}}, {"multi": true} )
Create new document if there is no existing one: "upsert"
db.logs.update( {name: "Dream Bender"}, {"$inc": {count: 1}}, {"upsert": true} )
相关文章
- MongoDB之集合管理一
- 想使用 MongoDB ,你应该了解这8个方面!
- python操作mongodb查询出现Object of type 'ObjectId' is not JSON serializable解决方法
- MongoDB Secondary 延时高(同步锁)问题分析
- MongoDB详解(二)——MongoDB架构与原理
- MongoDB云数据库常见问题诊断
- MongoDB writeConcern原理解析
- MongoDB复制集自适应oplog管理
- Nodejs学习笔记(四)——支持Mongodb
- 最全总结 | 聊聊 Python 数据处理全家桶(MongoDB 篇)
- Mongodb 性能测试
- Docker学习笔记17:docker实例之安装 Node.js、PHP、MySQL、Tomcat、Python、Redis、MongoDB、Apache
- 保存mnist到mongodb