On this page本页内容
db.collection.drop(<options>)
This is a mongosh
method. This is not the documentation for Node.js
or other programming language specific driver methods.
In most cases, mongosh
methods work the same way as the legacy mongo
shell methods. However, some legacy methods are unavailable in mongosh
.
For the legacy mongo
shell documentation, refer to the documentation for the corresponding MongoDB Server release:
For MongoDB API drivers, refer to the language specific MongoDB driver documentation.
Removes a collection or view from the database. 从数据库中删除集合或视图。The method also removes any indexes associated with the dropped collection. 该方法还删除与删除的集合关联的所有索引。The method provides a wrapper around the 该方法提供了drop
command.drop
命令的包装。
For a sharded cluster, if you use 对于分片集群,如果使用db.collection.drop()
and then create a new collection with the same name, you must either:db.collection.drop()
,然后创建同名的新集合,则必须执行以下操作之一:
mongos
using flushRouterConfig
.flushRouterConfig
刷新每个mongos
上的缓存路由表。db.collection.remove()
to remove the existing documents and reuse the collection. db.collection.remove()
删除现有文档并重用集合。db.collection.drop()
has the form:具有以下形式:
db.collection.drop( { writeConcern: <document> } )
db.collection.drop()
takes an optional document with the following field:采用具有以下字段的可选文档:
writeConcern |
|
|
db.collection.drop()
method and drop
command create an invalidate
Event for any Change Streams opened on dropped collection.db.collection.drop()
方法和drop
命令为在删除的集合上打开的任何更改流创建一个invalidate
事件。db.collection.drop()
method and drop
command abort any in-progress index builds on the target collection before dropping the collection. db.collection.drop()
方法和drop
命令会中止目标集合上的任何正在进行的索引。abort
oplog entry. primary
上指定索引的正在进行的构建,如果成功,将创建关联的异常abort
oplog条目。Secondary
成员在提交或中止索引生成之前,会等待来自主版本的提交或中止oplog条目。drop
command and the db.collection.drop()
method return an error if you try to drop a collection in the admin database or the config database from a mongos
. mongos
中删除admin
数据库或config
数据库中的集合,drop
命令和db.collection.drop()
方法将返回错误。config
服务器并在那里运行命令。admin
数据库或config
数据库中的集合可能会使集群处于不可用状态。Changed in version 4.2.在版本4.2中更改。
db.collection.drop()
obtains an exclusive lock on the specified collection for the duration of the operation. 在操作期间获取指定集合的独占锁。All subsequent operations on the collection must wait until 集合上的所有后续操作必须等待db.collection.drop()
releases the lock.db.collection.drop()
释放锁。
Prior to MongoDB 4.2, 在MongoDB 4.2之前,db.collection.drop()
obtained an exclusive lock on the parent database, blocking all operations on the database and all its collections until the operation completed.db.collection.drop()
获得了父数据库的独占锁,阻塞了数据库及其所有集合上的所有操作,直到操作完成。
The following operation drops the 以下操作将students
collection in the current database.students
集合放入当前数据库中。
db.students.drop()
w: 1
Write Concernw:1
写入关注点删除集合The following operation drops the 以下操作将students
collection in the current database. students
集合放入当前数据库中。The operation uses the 操作使用1
write concern:1
写入关注点:
db.students.drop( { writeConcern: { w: 1 } } )