mongodbHow to drop a collection in MongoDB?
To drop a collection in MongoDB, use the drop()
method. This method will delete the specified collection from the current database.
Example
db.collection.drop()
Output example
true
The drop()
method takes no arguments and returns true
if the collection was dropped successfully, or false
if the collection does not exist.
Code explanation
db
: The database object.collection
: The name of the collection to be dropped.drop()
: The method used to drop the collection.
Helpful links
More of Mongodb
- How to use watch in MongoDB?
- How to use triggers in MongoDB?
- What is MongoDB default port?
- How to use regex in MongoDB?
- How to use MongoDB query with "or" condition?
- How to use MongoDB queue?
- How to join two collections in MongoDB?
- How to query with "not equal" condition in MongoDB?
- How to list MongoDB users?
- How to use unwind in MongoDB?
See more codes...