run · write

update

storage.run({ action: "update", collection, filter, update, many, all })

Changes documents that match. Operators only, and an empty filter has to be meant.

document databasefreeone by default
Using Python?

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

Parameters

collectionstringrequired

Which collection.

filterJSON textrequired*

Which documents. Empty needs all: true.

updateJSON textrequired

Operators — $set, $inc, $unset, $push. A plain document is refused.

manyboolean

true updates every match. Default: one.

allboolean

Required to accept an empty filter.

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}

A whole document is refused

Passing a document would replace it, fields and all

{ active: false } does not mean « set active to false » — it means « this is now the entire document », and every other field is gone. The refusal exists because that mistake is silent and irreversible.

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

One by default, many on request

You writeIt touches
filter, nothing elsethe first match
filter, many: trueevery match
empty filterrefused
empty filter, all: trueevery document in the collection

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.