← Back to MongoDB Course | Chapter 5: CRUD — Delete | Lesson 1 of 6

deleteOne() का उपयोग

deleteOne filter match करने वाला पहला document remove करता है।

In this page:

  1. deleteOne()
Syntax
javascript
db.collection_name.deleteOne(filter)

deleteOne()

db.collection.deleteOne(filter) ज़्यादा से ज़्यादा एक matching document delete करता है और deletedCount return करता है। यह sure होने के लिए कि कौन-सा document जाता है _id जैसा एक unique filter इस्तेमाल करें। Backups न होने पर Deletion permanent है।

Note: जब आपको एक specific document delete करना हो _id से filter करें।

उदाहरण: deleteOne()

bash
test> db.users.insertMany([{ _id: 1, name: "Ada" }, { _id: 2, name: "Bob" }, { _id: 3, name: "Bob" }])
{ acknowledged: true, insertedIds: { '0': 1, '1': 2, '2': 3 } }
test> db.users.deleteOne({ name: "Bob" })
{ acknowledged: true, deletedCount: 1 }
test> db.users.deleteOne({ name: "Nobody" })
{ acknowledged: true, deletedCount: 0 }
test> db.users.find()
[ { _id: 1, name: 'Ada' }, { _id: 3, name: 'Bob' } ]

⚠️ Run this in your own terminal or Node.js environment.

Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. deleteOne को एक vague filter के साथ इस्तेमाल करना
  2. यह भूल जाना कि deletes undo नहीं हो सकते
  3. कोई filter pass न करना
चैप्टर सारांश
  • deleteOne एक match remove करता है
  • deletedCount return करता है
  • एक unique filter इस्तेमाल करें
  • Deletion permanent है
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.