On this page本页内容
drop
¶The drop
command removes an entire collection from a database. The command has following syntax:
The command takes the following fields:
drop |
The name of the collection to drop. |
writeConcern |
When issued on a sharded cluster, |
comment |
A comment can be any valid BSON type (string, integer, object, array, etc).
|
The mongo
shell provides the equivalent helper method db.collection.drop()
.
db.collection.drop()
method and drop
command abort any in-progress index builds on the target collection before dropping the collection. Prior to MongoDB 4.4, attempting to drop a collection with in-progress index builds results in an error, and the collection is not dropped.
For replica sets or shard replica sets, aborting an index on the primary does not simultaneously abort secondary index builds. MongoDB attempts to abort the in-progress builds for the specified indexes on the primary and if successful creates an associated abort
oplog entry. Secondary members with replicated in-progress builds wait for a commit or abort oplog entry from the primary before either committing or aborting the index build.
drop
command and its helper db.collection.drop()
create an invalidate Event for any Change Streams opened on the dropped collection.Changed in version 4.2.在版本4.2中更改。
drop
obtains an exclusive lock on the specified collection for the duration of the operation. All subsequent operations on the collection must wait until drop
releases the lock.
Prior to MongoDB 4.2, drop
obtained an exclusive lock on the parent database, blocking all operations on the database and all its collections until the operation completed.