参数
collectionstring必填哪个收藏
filterJSON text必填*文档。空需要 all: true.
updateJSON text必填操作员 - $set, $inc, $unset, $push拒绝提供普通文件。
manybooleantrue 默认值: 1。
allboolean需要接受空过滤器 。
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}})默认发生一个, 许多人应请求
| 你写 | 触动 |
|---|---|
| 过滤器,无其他 | 第一局第一局 |
| 筛选器, 多个: 真实 | 每个匹配 |
| 空空过滤器 | 拒绝拒绝 |
| 空过滤器, 全部: 真实 | 收藏中的每一文档 |
默认的缺省在于保守地阅读模糊不清的请求。 many: true 当你说真的时, matchedCount 与你所期待的相悖。
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 和 modifiedCount 当文件已经具有了价值时,则有不同之处——匹配但未作更改,这并非失败。