# هذا

Canonical URL: https://developers.iagenify.com/ar/sdk/ref/connected-storage/run-write/save/
Language: ar

`storage.run({ action: "save", collection, data })`

يدرج مستنداً، أو يستبدل الواحد بمُعَرِّف نفسه. الـ كتابة.

Status: document database · free · insert or replace

## المعاملات {#parameters}

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `collection` | string | مطلوب | -أيّ جمع جمع |
| `data` | JSON text | مطلوب | الوثيقة مع `_id` بدلاً من؛ بدون، يُدرج. |

```javascript
// No _id: inserted
await storage.run({ action: "save", collection: "profiles",
  data: JSON.stringify({ email: "a@example.com", plan: "go" }) });
// { ok: true, id: "66f0…" }

// With _id: replaced, or created if it is not there
await storage.run({ action: "save", collection: "profiles",
  data: JSON.stringify({ _id: "66f0…", email: "a@example.com", plan: "starter" }) });
// { ok: true, id: "66f0…", modifiedCount: 1 }
```

## لماذا هذا بدلاً من أن يدرج {#idempotent}

|  | ما يلي: | هذا |
| --- | --- | --- |
| مر مر مر مر مر مران | وثيقةان | أولاً - وثيقة واحدة |
| يحتاج إلى الهوية الأولى | لا: | يستعاض عن |
| جيد لـ | الأحداث، السجلات، أي شيء يُضاف إلى | التي لها هوية |

> **هذا هو الشخص الذي يمكن الوصول إليه في وظيفة قد تجري مرتين**
>
> ثم يُعاد تسليمها ، او يُعاد تسليمها ، او يُعاد استيرادها ، مع اضافة كل محاولة الى بعضها ، مما يزيد من صفها ، والاضافية الى ان المحاولة الثانية تقع على الاول ولا يوجد شيء مُكرَّر .

## يستبدل الحقول التي يحملها {#merge}

ان المستند الذي تمرره مثبت فوق الموجود ، فالحقول التي تتركها ليست مزالة ، ولكن الحقول التي تشملها مكتوبة بشكل غير رسمي — لذلك اصنع كل ما تعنيه ، بدلا من ان تكون شظية .

```javascript
// To change one field and leave the rest alone, update is the clearer tool
await storage.run({ action: "update", collection: "profiles",
  filter: JSON.stringify({ _id: id }),
  update: JSON.stringify({ $set: { plan: "starter" } }) });
```

- [ما يلي:](/ar/sdk/ref/connected-storage/run-write/insert): "الـ "كوان شاك" و "أ" و "جوتر
- [المستكمل](/ar/sdk/ref/connected-storage/run-write/update): تغيير في تغيير في تغيير في تغيير في الـ "التغيير"
- [run()](/ar/sdk/ref/connected-storage/run): إلى حد ما أفعال، مثل garede-fuus و se que chacune coamte.

```python
import json

# No _id: inserted
storage.run(action="save", collection="profiles",
            data=json.dumps({"email": "a@example.com", "plan": "go"}))
# {"ok": True, "id": "66f0…"}

# With _id: replaced, or created if it is not there
storage.run(action="save", collection="profiles",
            data=json.dumps({"_id": "66f0…", "email": "a@example.com", "plan": "starter"}))
# {"ok": True, "id": "66f0…", "modifiedCount": 1}
```

```python
import json

# To change one field and leave the rest alone, update is the clearer tool
storage.run(action="update", collection="profiles",
            filter=json.dumps({"_id": profile_id}),
            update=json.dumps({"$set": {"plan": "starter"}}))
```
