MongoDB Delete Records In Hindi | Delete Documents In MongoDB In Hindi

📔 : MongoDB 🔗

पिछले 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 करना चाहता हैं।

MognoDB deleteOne() Example

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 कर सकते हैं।

MongoDB deleteMany() Example

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 करना समझ आ गया होगा।

Related Topics :

Rahul Kumar

Rahul Kumar

Hi ! My name is Rahul Kumar Rajput. I'm a back end web developer and founder of learnhindituts.com. I live in Uttar Pradesh (UP), India and I love to talk about programming as well as writing technical tutorials and tips that can help to others.

Get connected with me. :) LinkedIn Twitter Instagram Facebook

b2eprogrammers