Remove () method
The Remove () method of MongoDB is used to remove a document from the collection. The Remove () method accepts two parameters. The first one is to delete the criteria, the second is the JUSTONE flag:
Deletion criteria: (optional) Delete the standard, depending on the file will be deleted.
Justone: (optional) If set to TRUE or 1, then delete only one file.
Grammar:
The basic syntax of the Remove () method is as follows
>db. Collection_name. Remove(delletion_critteria)
Example
Consider the following data MyCol collection.
{ "_ID" : ObjectId(5983548781331adf45ec5), "Title":"MongoDB Overview"}{ "_id" : objectid ( 5983548781331adf45ec6 "title" : "NoSQL Overview" }{ "_id" : objectid5983548781331adf45ec7 " Title ":" Yiibai Overview "}
The following example will delete all the files whose title is ' MongoDB Overview '
>Db.MyCol.Remove({' Title ':' MongoDB Overview '})>Db.MyCol.Find(){ "_id" : objectid (5983548781331adf45ec6 "title" : "NoSQL Overview" Span class= "pun" >}{ "_id" : objectid ( 5983548781331adf45ec7 "title" : "Yiibai Overview" }>
Remove only one
If you have more than one record and you want to delete only the first record, set the Justone parameter in the Remove () method
>db. Collection_name. Remove(deletion_criteria,1)
Delete all Files
If you do not specify a delete condition, then MongoDB will delete the entire file from the collection. This is equivalent to the SQL TRUNCATE command.
>db. MyCol. Remove()>db. MyCol. Find()>
MongoDB Tutorial Lesson nineth MongoDB Delete Document