Delete Collection in MongoDB

Drop () method in MongoDB

The db.collection.drop () method in MongoDB is used to delete a Collection from the database.

Syntax

The basic syntax of the drop () command is as follows:

 db . COLLECTION_NAME . drop () 

For example

First, you check the available Collections within the mydb database.

 > use mydb switched to db mydb > show collections mycol mycollection system . indexes tutorialspoint > 

Now, delete the Collection as mycollection as follows:

 > db . mycollection . drop () true > 

Then, check the Collection again inside the database:

 > show collections mycol system . indexes tutorialspoint > 

The drop () method will return true, if the selected Collection is successfully deleted, otherwise, it will return false.

According to Tutorialspoint

Previous post: Create Collection in MongoDB

Next lesson: Data type in MongoDB

4 ★ | 2 Vote

May be interested

  • Delete Database in MongoDBDelete Database in MongoDB
    the db.dropdatabase () command in mongodb is used to delete an existing database.
  • Limitations of indexes in MongoDBLimitations of indexes in MongoDB
    each index not only occupies part of the memory space but also causes an overhead on each insert, update, and delete operation. so, if you rarely use your collection for read operations, you should not use the index for it.
  • Advantages of MongoDBAdvantages of MongoDB
    any relation database has a unique schema design to index the data tables and relationships between those tables. meanwhile in mongodb there is no concept of relationship.
  • Data type in MongoDBData type in MongoDB
    mongodb supports many different data types. the following are some typical data types.
  • MongoDB malicious code attacks more than 26,000 victims in a weekMongoDB malicious code attacks more than 26,000 victims in a week
    malware that attacks the mongodb database has rekindled last week and after the weekend with the arrival of three new groups hijack more than 26,000 servers, of which one group attacked 22,000 machines.
  • Learn about security features and authentication in MongoDBLearn about security features and authentication in MongoDB
    in the following article, we will continue to introduce security and authentication features in the mongodb database management system series. in essence, the basic account validation feature is available in mongodb, but has been disabled in default mode, and in this mode the system requires at least 1 active database ...
  • ObjectId in MongoDBObjectId in MongoDB
    you have seen the use of mongodb objectid in previous chapters. in this chapter, we will understand the structure of objectid.
  • Insert Document in MongoDBInsert Document in MongoDB
    to insert data into collection in mongodb, you need to use the insert () or save () method.
  • Auto-Increment Sequence in MongoDBAuto-Increment Sequence in MongoDB
    mongodb does not have the auto-increment out-of-the-box feature like sql database. by default, it uses a 12-byte objectid for the _id field as the primary key to uniquely identify the documents. however, there are situations when we want the _id field to have some values ​​that automatically increase beyond objectid.
  • Shard in MongoDBShard in MongoDB
    sharding is a process of storing data records across multiple devices and it is a method of mongodb to meet the requirement for increasing data. when the size of the data increases, a single device cannot be enough to store data.