[MongoDB] Remove, update, create document
MongoDB create update Document remove
2023-09-14 08:59:20 时间
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系统学习之二】mongodb的启动
- mongodb centos7上的安装
- java操作mongodb时,对象bean和DBObject相互转换的方法
- 专访MongoDB官方大中华区首席架构师唐建法:MongoDB将会领导数据处理新趋势 —— 一个操作型的数据平台
- MongoDB 3.4 功能改进一览
- MongoDB · 最佳实践 · 短连接Auth性能优化
- 安装 php_mongodb.dll的坑
- Restful: Spring Boot with Mongodb
- MongoDB最简单的入门教程之五-通过Restful API访问MongoDB
- 前端MVC学习总结(四)——NodeJS+MongoDB+AngularJS+Bootstrap书店示例
- 【MongoDB】The Access control of mongodb
- MongoDB 数据库安装
- 【MongoDB】Serveral common command of MongoDb
- 【MongoDB】在windows平台mongodb切片集群(三)
- MongoDB -- 更新
- MongoDB(八)Mongodb——GridFS存储
- mongodb 3.2配置内存缓存大小为MB/MongoDB 3.x内存限制配置
- Python 操作 mongodb 亿级数据量使用 Bloomfilter 高效率判断唯一性 例子
- MongoDB高可用集群搭建(主从、分片、路由、安全验证)
- 将MongoDB部署到分布式集群(实操)
- Mongodb的基本使用