MongoDB Delete Collection |
-- Learning is not just about technology, but also about dreams!
- Home
- HTML
- JavaScript
- CSS
- Vue
- React
- Python3
- Java
- C
- C++
- C#
- AI
- Go
- SQL
- Linux
- VS Code
- Bootstrap
- Git
- Local Bookmarks
MongoDB Tutorial
MongoDB Tutorial NoSQL Introduction MongoDB Introduction Windows MongoDB Linux MongoDB OSX MongoDB MongoDB Shell MongoDB Concept Analysis MongoDB User Management MongoDB Connection MongoDB Create Database MongoDB Drop Database MongoDB Create Collection MongoDB Rename Collection MongoDB Delete Collection MongoDB Insert Document MongoDB Update Document MongoDB Delete Document MongoDB Query Document MongoDB Conditional Operators MongoDB $type Operator MongoDB Limit and Skip Methods MongoDB Sort MongoDB Index MongoDB Aggregation MongoDB Replication (Replica Set) MongoDB Sharding MongoDB Backup and Restore MongoDB Monitoring MongoDB Java MongoDB PHP Extension MongoDB PHP MongoDB PHP7 Node.js MongoDB
MongoDB Advanced Tutorial
MongoDB Relationships MongoDB Database References MongoDB Covered Index Query MongoDB Query Analysis MongoDB Atomic Operations MongoDB Advanced Indexing MongoDB Index Limitations MongoDB ObjectId MongoDB Map Reduce MongoDB Full Text Search MongoDB Regular Expression MongoDB Management Tool MongoDB GridFS MongoDB Capped Collections MongoDB Auto-increment
MongoDB Delete Collection
In this chapter, we will introduce how to use MongoDB to delete a collection.
MongoDB uses the drop() method to delete a collection.
The drop() method can permanently delete the specified collection and all its documents from the database. This is an irreversible operation, so it should be used with caution.
Syntax Format:
db.collection.drop()
Parameter Description:
- None
Return Value
If the selected collection is successfully deleted, the drop() method returns true, otherwise it returns false.
Example
In the database mydb, we can first view the existing collections using the show collections command:
> use mydb
switched to db mydb
> show collections
mycol
mycol2
system.indexes
>
Next, delete the collection mycol2:
> db.mycol2.drop()
true
>
View the collections in database mydb again using show collections:
> show collections
mycol
system.indexes
>
From the results, it can be seen that the mycol2 collection has been deleted.
YouTip