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
You should read it
- Overview of MongoDB
- Capped Collection in MongoDB
- Query Document in MongoDB
- MongoDB malicious code attacks more than 26,000 victims in a week
- Learn about security features and authentication in MongoDB
- Index (Mong) in MongoDB
- Reference Database in MongoDB
- Compare the performance of MongoDB and SQL Server 2008
May be interested
- Delete Database in MongoDBthe db.dropdatabase () command in mongodb is used to delete an existing database.
- Limitations of indexes in MongoDBeach 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 MongoDBany 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 MongoDBmongodb supports many different data types. the following are some typical data types.
- MongoDB malicious code attacks more than 26,000 victims in a weekmalware 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 MongoDBin 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 MongoDByou have seen the use of mongodb objectid in previous chapters. in this chapter, we will understand the structure of objectid.
- Insert Document in MongoDBto insert data into collection in mongodb, you need to use the insert () or save () method.
- Auto-Increment Sequence in MongoDBmongodb 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 MongoDBsharding 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.