MongoDB - Delete Document
MongoDB - Delete Document : discover ways to delete a file the usage of MongoDB.
The cast off() Method
MongoDB's do away with() technique is used to dispose of a document from the gathering.Eliminate() approach accepts two parameters. One is deletion criteria and second is justOne flag.
eliminate() technique accepts parameters. One is deletion criteria and 2nd is justOne flag.
deletion criteria − (Optional) deletion standards in step with files may be eliminated.
justOne − (Optional) if set to actual or 1, then do away with handiest one report.
SyntaxThere are following Basic syntax of remove() method
ExampleConsider the mycol collection has the following data.
"_id" : ObjectId(??4LLgt_QzPk), "identify":"MongoDB Overview" "_id" : ObjectId(VsyR6t8Xf+%3), "title":"NoSQL Overview" "_id" : ObjectId(@JNq+W$f7N5B), "title":"Welookups"Following example will eliminate all of the documents whose identify is 'MongoDB Overview'.
>db.Mycol.Eliminate('identify':'MongoDB Overview') >db.Mycol.Locate() "_id" : ObjectId(VsyR6t8Xf+%three), "title":"NoSQL Overview" "_id" : ObjectId(@JNq+W$f7N5B), "title":"Welookups" >
Remove Only OneIf there are a couple of facts and also you need to delete simplest the first report, then set justOne parameter in take away() approach.
Remove All DocumentsThis is equal of SQL's truncate command.
>db.mycol.take away() >db.mycol.locate() >