Parâmetros
collectionstringobrigatórioQuale collezion.
filterJSON textobrigatório*Quali documenti. Necessita vat all: true.
updateJSON textobrigatórioOperatori — $set, $inc, $unset, $push. Un documente plain è respinse.
manybooleantrue aggiorna ogni match. Predefinito: un.
allbooleanObligatoriu di accettare un filtro vuoto.
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}Un documentu intero è respinse
{ active: false } non significa « set active to false » — significa « questo è ora l'intero documento » e ogni altro campo è partito. Il renegazione esiste perché quel erro è silente e irreversibile.
// 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}})Uno per default, molti su richiesta
| Tu scrivi | Toca |
|---|---|
| Filtro, ningun altro | la prima partida |
| filtri, molti: verit | Cada fèrs |
| Filtro vazio | - Negati |
| Filtro vuoto, tutto: vero | Cada documento della collezion |
Il predefinit di una è la lectura conservatrice di una richiesta ambigua. Di many: true quando lo si dice — e lee matchedCount a contra di ciò che si aspettava.
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 e modifiedCount differiscono quando un documento aveva già il valore — igual ma non cambiato.