If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
पिछले topic में आपने Collection (Table) से documents को update करना सीखा , इस topic में हम collection को delete करना सीखेंगे।
MongoDB में documents / records को delete करने के दो तरीके है -
deleteOne()
: single document delete करने के लिए।
deleteMany()
: multiple document delete करने के लिए।
दोनों ही function में 1 argument pass होता है जो optional रहता है , जिसके bases पर आप documents / records find करके delete करना चाहता हैं।
deleteOne()
method , pass की गयी query से match करने वाले पहले document को delete करता है।
db.users.deleteOne({"name" : "Pyare Lal"})
अगर record delete हुआ होगा तो deletedCount
की value 1 मिलेगी जैसे नीचे output में दिख रही है।
{ "acknowledged" : true, "deletedCount" : 1.0 }
बाकी आप अपनी need के according conditions pass कर सकते हैं।
●●●
deleteMany()
method , pass की गयी query से match करने वाले सभी documents/records को delete करता है।
db.users.deleteMany({"name" : "Pyare Lal"})
और अगर आप Collection के सभी documents को एक साथ delete करना चाहते हैं तो deleteMany()
method को बिना condition के use करें।
db.users.deleteMany()
I Hope , आपको MongoDB में documents को delete करना समझ आ गया होगा।
●●●
Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)
Get connected with me. :) LinkedIn Twitter Instagram Facebook