المعاملات
collectionstringمطلوب-أيّ جمع جمع
filterJSON textمطلوب*أي وثائق. all: true.
updateJSON textمطلوبعمال التشغيل $set, $inc, $unset, $pushوثيقة بسيطة مرفوضة
manybooleantrue تحديثات كل متطابق. الإفتراضي: واحد.
allbooleanإلى معاينة a فارغ.
await storage.run({
action: "update",
collection: "users",
filter: JSON.stringify({ email: "a@example.com" }),
update: JSON.stringify({ $set: { active: false }, $inc: { logins: 1 } }),
});
// { matchedCount: 1, modifiedCount: 1 }import json
storage.run(
action="update",
collection="users",
filter=json.dumps({"email": "a@example.com"}),
update=json.dumps({"$set": {"active": False}, "$inc": {"logins": 1}}),
)
# {"matchedCount": 1, "modifiedCount": 1}رفض تقديم وثيقة كاملة
}الأنشطة: كاذبة} لا تعني "الأنشطة النشطة للتزوير" - وهذا يعني أن "هذه هي الآن الوثيقة بأكملها، وكل حقل آخر قد اختفى، والرفض موجود لأن هذا الخطأ صامت ولا رجعة فيه.
// Refused
update: JSON.stringify({ active: false })
// Meant
update: JSON.stringify({ $set: { active: false } })# Refused
update = json.dumps({"active": False})
# Meant
update = json.dumps({"$set": {"active": False}})واحد بالتخلف، وكثير من الطلب
| تكتب | "تلمس" |
|---|---|
| لا شيء آخر | الـ الأول |
| مُنت كثيرة: | كل ما يتطابق |
| لا | لا شيء |
| لا فارغ، كل: fi حقيقي | كل وثيقة من وثائق جمع |
The default of one is the conservative reading of an ambiguous request. Say many: true when you mean it — and read matchedCount against what you expected.
const res = await storage.run({ action: "update", collection, filter, update, many: true });
if (res.matchedCount !== expected) {
console.warn(`expected ${expected}, matched ${res.matchedCount}`);
}res = storage.run(action="update", collection=collection, filter=filter, update=update, many=True)
if res["matchedCount"] != expected:
print(f"expected {expected}, matched {res['matchedCount']}")matchedCount and modifiedCount differ when a document already had the value — matched but not changed. That is not a failure.