drop
drop
- The
drop
command removes an entire collection from adatabase. The command has following syntax:
- { drop: <collection_name>, writeConcern: <document>}
The command takes the following fields:
FieldDescriptiondropThe name of the collection to drop.writeConcernOptional. A document expressing the write concern of the drop
command.Omit to use the default write concern.
When issued on a sharded cluster, mongos
converts thewrite concern of thedrop
command and its helperdb.collection.drop()
to "majority"
.
The mongo
shell provides the equivalent helper methoddb.collection.drop()
.
Behavior
This command also removes any indexes associated with the droppedcollection.
Starting in MongoDB 4.0.2, dropping a collection deletes itsassociated zone/tag ranges.
The drop
command and its helperdb.collection.drop()
create an invalidate Eventfor any Change Streams opened on the dropped collection.
Resource Locking
Changed in version 4.2.
drop
obtains an exclusive lock on the specified collectionfor the duration of the operation. All subsequent operations on thecollection must wait until drop
releases thelock.
Prior to MongoDB 4.2, drop
obtained an exclusivelock on the parent database, blocking all operations on thedatabase and all its collections until the operation completed.