Navigation
This version of the documentation is archived and no longer supported.

drop

On this page

Syntax

drop

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

Tip

In the mongo Shell, this command can also be run through the drop helper method.

Helper methods are convenient for mongo users, but they may not return the same level of information as database commands. In cases where the convenience is not needed or the additional return fields are required, use the database command.

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

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".

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

Behavior

This command also removes any indexes associated with the dropped collection.

Dropping a collection deletes its associated zone/tag ranges.

The drop command and its helper db.collection.drop() create an invalidate for any Change Streams opened on the dropped collection.

Resource Locking

Changed in version 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.

←   currentOp dropDatabase  →