MongoDB Remove Document-Programmershelper

0
236
Spread the love

Introduction

This article will provide step by step basic concept of MongoDB. where you can easily understand the core concept of MongoDB.The remove method () is used to remove the existing record in a collection.The following method <db.collection.Remove> is used to Delete a document

Prerequisite

It would be better if you have the basic knowledge of RDBMS concept. Actually, you are going to learn a high-performance database.It will good to cover my below articles before this.Its help to learn more about MongoDB.You should also read my previous articles.In which I explained MongoDB update document step by step guideline and MongoDB save a document.

Implementation Section

  • Complete document removes using remove method().
  • Remove multiple documents using remove many() method.
  • How can remove single item using RemoveOne Method ( )?

Syntax

Example

Delete a document:
db.<collection_name>.remove({“gender”: “male” })

  • <db> is a reserved word.
  • <Collection_name> writes the collection name.
  • <Remove> is also reserverd word used for Remove the existing record in collection.
  • Inside the bracket write the document <specific_criteria for Remove data>.

Practical work

Complete document removes using remove method()

It may be a good work.if you run a find method() before removing a document.so I performed it.

output

Alt tag MongoDB remove document

If you do not define specific criteria than delete query deletes all the record from collection.this is same SQL truncate command.

Syntax

Output:

Alt tag MongoDB remove document                               
Remove multiple documents using RemoveMany method()

if you want to delete more than one records than<deleteMany>method deletes all the document that match specific criteria.

Syntax

output

Alt Tag MongoDB remove document

  How can remove single item using RemoveOne Method()

If you want to delete one of them. then simply use a <removeOne>method.

Syntax

Output

Conclusion

I wish I could tell you that a great site of MongoDB.you just understands key element above post-MongoDB remove document. for more detail, MongoDB remove document.You also read my previous lecture.I hope you will understand this lecture.Thank you for reading this lecture. Hope you got the idea.