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 check the version of MongoDB?
- How to use eq in MongoDB?
- How to update many documents in MongoDB?
- How to list databases in MongoDB?
- How to rename a MongoDB collection?
- How to insert many docs in MongoDB?
- How to export an entire MongoDB database?
- How to use hint in MongoDB?
- How to set MongoDB oplog?
See more codes...