19.Delete Documents-官方文档摘录
1 插入例子
db.inventory.insertMany( [
{ item: "journal", qty: 25, size: { h: 14, w: 21, uom: "cm" }, status: "A" },
{ item: "notebook", qty: 50, size: { h: 8.5, w: 11, uom: "in" }, status: "P" },
{ item: "paper", qty: 100, size: { h: 8.5, w: 11, uom: "in" }, status: "D" },
{ item: "planner", qty: 75, size: { h: 22.85, w: 30, uom: "cm" }, status: "D" },
{ item: "postcard", qty: 45, size: { h: 10, w: 15.25, uom: "cm" }, status: "A" },
]);
2 删除所有
db.inventory.deleteMany({})
3 删除匹配的行
db.inventory.deleteMany({ status : "A" })
4 删除最多一行记录
db.inventory.deleteOne( { status: "D" } )
5 注意
1.删除对应元素并不会删除对应的索引
2.删除具有原子性
This page provides examples of delete operations using the following methods in the mongo
shell:
The examples on this page use the inventory
collection. To populate the inventory
collection, run the following:
db.inventory.insertMany( [
{ item: "journal", qty: 25, size: { h: 14, w: 21, uom: "cm" }, status: "A" },
{ item: "notebook", qty: 50, size: { h: 8.5, w: 11, uom: "in" }, status: "P" },
{ item: "paper", qty: 100, size: { h: 8.5, w: 11, uom: "in" }, status: "D" },
{ item: "planner", qty: 75, size: { h: 22.85, w: 30, uom: "cm" }, status: "D" },
{ item: "postcard", qty: 45, size: { h: 10, w: 15.25, uom: "cm" }, status: "A" },
]);
You can run the operation in the web shell below:
Delete All Documents
To remove all documents from a collection, pass an empty filter document {}
to thedb.collection.deleteMany()
method.
The following example deletes all documents from the inventory
collection:
db.inventory.deleteMany({})
The method returns a document with the status of the operation. For more information and examples, seedeleteMany()
.
Delete All Documents that Match a Condition
You can specify criteria, or filters, that identify the documents to delete. The filters use the same syntax as read operations.
To specify equality conditions, use <field>:<value>
expressions in the query filter document:
{ <field1>: <value1>, ... }
A query filter document can use the query operators to specify conditions in the following form:
{ <field1>: { <operator1>: <value1> }, ... }
To delete all documents that match a deletion criteria, pass a filter parameter to the deleteMany()
method.
The following example removes all documents from the inventory
collection where the status
field equals"A"
:
db.inventory.deleteMany({ status : "A" })
The method returns a document with the status of the operation. For more information and examples, seedeleteMany()
.
Remove Only One Document that Matches a Condition
To delete at most a single document that matches a specified filter (even though multiple documents may match the specified filter) use the db.collection.deleteOne()
method.
The following example deletes the first document where status
is "D"
.
db.inventory.deleteOne( { status: "D" } )
Delete Behavior
Indexes
Delete operations do not drop indexes, even if deleting all documents from a collection.
Atomicity
All write operations in MongoDB are atomic on the level of a single document. For more information on MongoDB and atomicity, see Atomicity and Transactions.
Write Acknowledgement
With write concerns, you can specify the level of acknowledgement requested from MongoDB for write operations. For details, see Write Concern.
19.Delete Documents-官方文档摘录的更多相关文章
- Cocos Creator 加载和切换场景(官方文档摘录)
Cocos Creator 加载和切换场景(官方文档摘录) 在 Cocos Creator 中,我们使用场景文件名( 可以不包含扩展名)来索引指代场景.并通过以下接口进行加载和切换操作: cc.dir ...
- ng的概念层次(官方文档摘录)
官方文档是这么说的: You write Angular applications by: composing HTML templates with Angularized markup, writ ...
- Cocos Creator 使用计时器(官方文档摘录)
在 Cocos Creator 中,我们为组件提供了方便的计时器,这个计时器源自于 Cocos2d-x 中的 cc.Scheduler,我们将它保留在了 Cocos Creator 中并适配了基于组件 ...
- angular 模板语法(官方文档摘录)
https://angular.cn/guide/template-syntax {{}} 和"" 如果嵌套,{{}}里面求完值,""就是原意 <h3&g ...
- Cocos Creator 生命周期回调(官方文档摘录)
Cocos Creator 为组件脚本提供了生命周期的回调函数.用户通过定义特定的函数回调在特定的时期编写相关 脚本.目前提供给用户的声明周期回调函数有: onLoad start update la ...
- Qt元类型(MetaType)注册入门(附一些官方文档的关键摘录)
昨天调试项目时,突然发现如下消息: QObject::connect: Cannot queue arguments of type 'ERROR_LEVEL' (Make sure 'ERROR_L ...
- 20191127 Spring Boot官方文档学习(9.1-9.3)
9."使用方法"指南 9.1.Spring Boot应用程序 9.1.1.创建自己的FailureAnalyzer FailureAnalyzer被包装在FailureAnalys ...
- Spring Data Commons 官方文档学习
Spring Data Commons 官方文档学习 -by LarryZeal Version 1.12.6.Release, 2017-07-27 为知笔记版本在这里,带格式. Table o ...
- hbase官方文档(转)
FROM:http://www.just4e.com/hbase.html Apache HBase™ 参考指南 HBase 官方文档中文版 Copyright © 2012 Apache Soft ...
- HBase 官方文档
HBase 官方文档 Copyright © 2010 Apache Software Foundation, 盛大游戏-数据仓库团队-颜开(译) Revision History Revision ...
随机推荐
- 关于Linux网卡调优之:RPS (Receive Packet Steering)
昨天在查LVS调度均衡性问题时,最终确定是 persistence_timeout 参数会使用IP哈希.目的是为了保证长连接,即一定时间内访问到的是同一台机器.而我们内部系统,由于出口IP相对单一,所 ...
- Pycharm 建立工程,包含多个工程目录
- orm工具的基本思想
orm工具的基本思想无论是用过的hibernate,mybatis,你都可以法相他们有一个共同点:1. 从配置文件(通常是XML配置文件中)得到 sessionfactory.2. 由sessionf ...
- 【BZOJ】1045: [HAOI2008]糖果传递(中位数)
http://www.lydsy.com/JudgeOnline/problem.php?id=1045 白书上有讲 没ac的坑点在,数据范围n<=1,000,000 #include < ...
- js调绝对定位的top
$("ggg div").each(function () { this.style.top = (parseFloat(this.style.top ...
- (转)session、cookie与“记住我的登录状态”的功能的实现
Cookie的机制 Cookie是浏览器(User Agent)访问一些网站后,这些网站存放在客户端的一组数据,用于使网站等跟踪用户,实现用户自定义功能. Cookie的Domain和Path属性标识 ...
- 过滤一个Collection最好的方法
private static List<Integer> filter(List<Integer> list){ Iterator<Integer> it = li ...
- 40 个顶级 jQuery 图片、内容滑块和幻灯片
在这个快速发展的网络世界中,我们使用图片.内容滑块和幻灯片来给网站实现良好.有吸引力的外观.你可以吸引浏览者借助图像滑块让网站更加具有活力.使用 JavaScript 可以轻松实现轻量级的图片和内容滑 ...
- 【黑金原创教程】【Modelsim】【第四章】激励文本就是仿真环境
声明:本文为黑金动力社区(http://www.heijin.org)原创教程,如需转载请注明出处,谢谢! 黑金动力社区2013年原创教程连载计划: http://www.cnblogs.com/ ...
- Memcached 之 .NET(C#)实例分析
一:Memcached的安装 step1. 下载memcache(http://jehiah.cz/projects/memcached-win32)的windows稳定版(这里我下载了memcach ...