C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
MongoDB Delete documentsIn MongoDB, the db.colloction.remove() method is used to delete documents from a collection. The remove() method works on two parameters. 1. Deletion criteria: With the use of its syntax you can remove the documents from the collection. 2. JustOne: It removes only one document when set to true or 1. Syntax: db.collection_name.remove (DELETION_CRITERIA) Remove all documentsIf you want to remove all documents from a collection, pass an empty query document {} to the remove() method. The remove() method does not remove the indexes. Let's take an example to demonstrate the remove() method. In this example, we remove all documents from the "TheDeveloperBlog" collection. db.TheDeveloperBlog.remove({}) Remove all documents that match a conditionIf you want to remove a document that match a specific condition, call the remove() method with the <query> parameter. The following example will remove all documents from the TheDeveloperBlog collection where the type field is equal to programming language. db.TheDeveloperBlog.remove( { type : "programming language" } ) Remove a single document that match a conditionIf you want to remove a single document that match a specific condition, call the remove() method with justOne parameter set to true or 1. The following example will remove a single document from the TheDeveloperBlog collection where the type field is equal to programming language. db.TheDeveloperBlog.remove( { type : "programming language" }, 1 )
Next TopicMongoDB Query Documents
|