drop

On this page本页内容

drop

The drop command removes an entire collection from a database. The command has following syntax:

{ drop: <collection_name>, writeConcern: <document>, comment: <any> }

The command takes the following fields:

Field字段Description描述
drop The name of the collection to drop.
writeConcern

Optional.可选。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 the write concern of the drop command and its helper db.collection.drop() to "majority".

comment

Optional.可选。A user-provided comment to attach to this command. Once set, this comment appears alongside records of this command in the following locations:

A comment can be any valid BSON type (string, integer, object, array, etc).

New in version 4.4.版本4.4中的新功能。

The mongo shell provides the equivalent helper method db.collection.drop().

Behavior行为

Resource Locking

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.