MongoDB Operations Manual Crud Remove Remove

Source: Internet
Author: User

Overview of deleting Recordsin MongoDB, the Db.collection.remove () method is used to delete records in the collection. You can delete all records, delete all eligible records, or delete only one record.
Delete all recordsdeletes all the records in a collection as long as an empty query object {} is passed to the Remove () method. The Remove () method does not delete the index.
Example:db.testData.remove ({});
using the Remove () method to delete all records in a collection may be more efficient than deleting the entire collection containing the index using the drop () method, and then rebuilding the collection and index.
Delete a record that matches a condition removes all eligible records from a collection, passing a query object to the Remove () method.
Example:db.testData.remove ({type: ' food '}); Records that all type fields will be deleted
for a large-scale delete operation, the Remove () operation may be more efficient if you want to copy some records into a new collection and then delete the entire collection with the drop () method.
Delete a single record that matches a condition to delete a record in a collection that matches a condition, you need to give the Remove () method a Justone parameter, set to Ture or 1
Example:db.testData.remove ({type: ' food '},1);
to delete a record in a collection that is arranged in a certain order, use the Findandmodify () method.

MongoDB Operations Manual Crud Remove Remove

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.