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.


There are following Basic syntax of remove() method


Consider 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')
 "_id" : ObjectId(VsyR6t8Xf+%three), "title":"NoSQL Overview"
 "_id" : ObjectId(@JNq+W$f7N5B), "title":"Welookups"

Remove Only One

If 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 Documents

This is equal of SQL's truncate command.
>db.mycol.take away()

Welookups is optimized for learning.Copy right 2018 - 2019 kumar aditya singh .
All Right Reserved and you agree to have read and accepted our term and condition.
All Rights Reserved.