- Reference >
mongoShell Methods >- Collection Methods >
- db.collection.drop()
db.collection.drop()¶
On this page
Definition¶
-
db.collection.drop()¶ 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
dropcommand.Note
For a sharded cluster, if you use
db.collection.drop()and then create a new collection with the same name, you must either:- Flush the cached routing table on every
mongosusingflushRouterConfig. - Use
db.collection.remove()to remove the existing documents and reuse the collection. Use this approach to avoid flushing the cache.
db.collection.drop()has the form:db.collection.drop()takes no arguments and will produce an error if called with any arguments.Returns: truewhen successfully drops a collection.falsewhen collection to drop does not exist.
- Flush the cached routing table on every
Behavior¶
This method obtains a write lock on the affected database and will block other operations until it has completed.
Example¶
The following operation drops the students collection in the
current database.