
- MongoDB Tutorial
- MongoDB - Home
- MongoDB - Overview
- MongoDB - Advantages
- MongoDB - Environment
- MongoDB - Data Modeling
- MongoDB - Create Database
- MongoDB - Drop Database
- MongoDB - Create Collection
- MongoDB - Drop Collection
- MongoDB - Data Types
- MongoDB - Insert Document
- MongoDB - Query Document
- MongoDB - Update Document
- MongoDB - Delete Document
- MongoDB - Projection
- MongoDB - Limiting Records
- MongoDB - Sorting Records
- MongoDB - Indexing
- MongoDB - Aggregation
- MongoDB - Replication
- MongoDB - Sharding
- MongoDB - Create Backup
- MongoDB - Deployment
- MongoDB - Java
- MongoDB - PHP
- Advanced MongoDB
- MongoDB - Relationships
- MongoDB - Database References
- MongoDB - Covered Queries
- MongoDB - Analyzing Queries
- MongoDB - Atomic Operations
- MongoDB - Advanced Indexing
- MongoDB - Indexing Limitations
- MongoDB - ObjectId
- MongoDB - Map Reduce
- MongoDB - Text Search
- MongoDB - Regular Expression
- Working with Rockmongo
- MongoDB - GridFS
- MongoDB - Capped Collections
- Auto-Increment Sequence
- MongoDB Useful Resources
- MongoDB - Questions and Answers
- MongoDB - Quick Guide
- MongoDB - Useful Resources
- MongoDB - Discussion
How to drop a collection in MongoDB?
To drop a collection in MongoDB, you need to use drop() command. The syntax is as follows:
db.yourCollectionName.drop();
The above syntax returns true or false. It returns true if the collection is dropped successfully otherwise false.
Let us first display all collection names from MongoDB. Here, we have a database ‘sample’ that contains some collections. First you need to switch to the ‘sample’ database. The query is as follows:
> use sample; switched to db sample
Now display all collection names with the help of show command. The query is as follows:
> show collections;
The following is the output:
bookInformation userInformation
Above, you can see we have the following two collections:
bookInformation
userInformation
Now let us drop the collection name ‘bookInformation’. The query is as follows:
> db.bookInformation.drop();
The following is the output displaying true:
true
The result true specify that we have dropped the collection successfully. Now you can display all the collection names with the help of show command to verify. The query is as follows:
> show collections;
The following is the output:
userInformation
Look at the above sample output, there is no collection with the name ‘bookInformation.’
- Related Articles
- How to drop a numeric collection from MongoDB?
- How to drop a MongoDB Collection using Java?
- How can I drop a collection in MongoDB with two dashes in the name?
- How to drop a database in MongoDB?
- How to drop a database in MongoDB using java?
- How to add a column in MongoDB collection?
- How to create a new collection in MongoDB?
- How to delete documents from a collection in MongoDB?
- How to retrieve documents from a collection in MongoDB?
- How to check empty field in a MongoDB collection?
- MongoDB: How to query a collection named “version”?
- How to create a MongoDB collection using Java?
- How to get array from a MongoDB collection?
- How to drop an index in MongoDB using Java?
- Clone a collection in MongoDB?
