MongoDB Delete Document


The db.collection.remove() method will remove the document or documents from the collection. It’s syntax is as follows
Syntax:

 db.collection.remove(   <query>,   <justOne>)

if justOne: set to true limits removal of documents to justOne instead of all if multiple records matched for the query


Example:-

>_ Remove a single document having userid “Andrew”

 >db.users.remove({userid:”Andrew”,justOne:true})

>_ Remove all users having Age >25

 >db.users.remove({Age:{$gt:25}})

>_ Remove all records of 'users' collection

 >db.users.remove({})
Copyright © 2018-2020 TutorialToUs. All rights reserved.