C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
MongoDB Drop collectionIn MongoDB, db.collection.drop() method is used to drop a collection from a database. It completely removes a collection from the database and does not leave any indexes associated with the dropped collections. The db.collection.drop() method does not take any argument and produce an error when it is called with an argument. This method removes all the indexes associated with the dropped collection. Syntax: db.COLLECTION_NAME.drop() MongoDB Drop collection exampleLet's take an example to drop collection in MongoDB. First check the already existing collections in your database. >use mydb Switched to db mydb > show collections SSSIT system.indexes Note: Here we have a collection named SSSIT in our database. Now drop the collection with the name SSSIT: >db.SSSIT.drop() True Now check the collections in the database: >show collections System.indexes Now, there are no existing collections in your database. Note: The drop command returns true if it successfully drops a collection. It returns false when there is no existing collection to drop.
Next TopicMongoDB Insert Documents
|