# updateOne और updateMany — MongoDB Fundamentals: Documents, Queries और Indexes

Source: https://www.skillbyai.com/hi/mongodb/mongo-update-basics

> updateOne और updateMany से documents बदलें और कई documents बदलने से पहले अपना filter test करें।

## updateOne()

फ़िल्टर से मेल खाने वाले पहले डॉक्यूमेंट को `$set` जैसे अपडेट ऑपरेटर से बदलता है।

```javascript
db.users.updateOne(
  { name: "Grace Hopper" },
  { $set: { role: "admiral" } }
)
```

Output:

```
{ acknowledged: true, matchedCount: 1, modifiedCount: 1 }
```

## updateMany()

वही विचार, पर हर मेल खाते डॉक्यूमेंट पर लागू होता है।

```javascript
db.users.updateMany(
  { role: "engineer" },
  { $set: { department: "platform" } }
)
```

Output:

```
{ acknowledged: true, matchedCount: 2, modifiedCount: 2 }
```

## फ़िल्टर में सटीक रहें

`updateMany()` में बहुत व्यापक फ़िल्टर उन डॉक्यूमेंट को भी चुपचाप बदल सकता है जिन्हें आप छूना नहीं चाहते थे — पहले फ़िल्टर को `find()` से जाँच लें।
