BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

Drop collection in MongoDB

Last Updated: September 16, 2017 by Chaitanya Singh | Filed Under: MongoDB Tutorial

In the previous tutorial we learned how to create collection in MongoDB. In this guide, we will see how to drop a collection in MongoDB.

To drop a collection , first connect to the database in which you want to delete collection and then type the following command to delete the collection:

db.collection_name.drop()

Note: Once you drop a collection all the documents and the indexes associated with them will also be dropped. To preserve the indexes we use remove() function that only removes the documents in the collection but doesn’t remove the collection itself and the indexes created on it. We will learn about indexes and remove() function in the later tutorials.

MongoDB drop collection Example

For example I want to delete a collection names “teachers” in my database “beginnersbook.com”. To do this I would write the following commands in the given sequence.

> use beginnersbookdb
switched to db beginnersbookdb

> show collections
beginnersbook
students
teachers

> db.teachers.drop()
true

> show collections
beginnersbook
students

As you can see that the command db.teachers.drop() returned true which means that the collection is deleted successfully. The same thing we have verified using the show collections command after deletion as shown above.
MongoDB drop collection

❮ PreviousNext ❯

Top Related Articles:

  1. Drop Database in MongoDB
  2. Mapping Relational Databases to MongoDB
  3. MongoDB Tutorial for Beginners
  4. Create Collection in MongoDB
  5. MongoDB sort() method

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

MongoDB Tutorial

  • MongoDB Tutorial
  • NoSQL Introduction
  • Introduction to MongoDB
  • Mapping Relational Database to MongoDB
  • Install MongoDB
  • Create Database
  • Drop Database
  • Create Collection
  • Drop Collection
  • Insert Document
  • Query Document
  • Update Document
  • Delete Document
  • MongoDB Projection
  • MongoDB limit() and skip()
  • MongoDB sorting
  • MongoDB Indexing

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap