& جاري

هذا

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

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

document databasefreeinsert or replace
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

المعاملات

collectionstringمطلوب

-أيّ جمع جمع

dataJSON textمطلوب

الوثيقة مع _id بدلاً من؛ بدون، يُدرج.

// 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 }
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}

لماذا هذا بدلاً من أن يدرج

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

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

يستبدل الحقول التي يحملها

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

// 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" } }) });
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"}}))