MongoDB Tutorial Lesson nineth MongoDB Delete Document

Source: Internet
Author: User
Tags mongodb tutorial

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:

    1. Deletion criteria: (optional) Delete the standard, depending on the file will be deleted.

    2. 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.