# Actualizzazione

Canonical URL: https://developers.iagenify.com/pt/sdk/ref/connected-storage/run-write/update/
Language: pt

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

Cambia documenti che coincide. Operatori solo, e un filtro vazio deve essere significat.

Status: document database · free · one by default

## Parâmetros {#parameters}

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `collection` | string | obrigatório | Quale collezion. |
| `filter` | JSON text | obrigatório* | Quali documenti. Necessita vat `all: true`. |
| `update` | JSON text | obrigatório | Operatori — `$set`, `$inc`, `$unset`, `$push`. Un documente plain è respinse. |
| `many` | boolean |  | `true` aggiorna ogni match. Predefinito: un. |
| `all` | boolean |  | Obligatoriu di accettare un filtro vuoto. |

```javascript
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 }
```

## Un documentu intero è respinse {#operators}

> **Passare un documente lo sostituirà, campi e tot**
>
> { 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.

```javascript
// Refused
update: JSON.stringify({ active: false })

// Meant
update: JSON.stringify({ $set: { active: false } })
```

## Uno per default, molti su richiesta {#scope}

| 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.

```javascript
const res = await storage.run({ action: "update", collection, filter, update, many: true });

if (res.matchedCount !== expected) {
  console.warn(`expected ${expected}, matched ${res.matchedCount}`);
}
```

`matchedCount` e `modifiedCount` differiscono quando un documento aveva già il valore — igual ma non cambiato.

- [-Supprimer](/pt/sdk/ref/connected-storage/run-write/delete): Le même garde-fou sur le filtre vide.
- [run()](/pt/sdk/ref/connected-storage/run): Tutes les actions, les garde-fous et ce que chaque coute.

```python
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}
```

```python
# Refused
update = json.dumps({"active": False})

# Meant
update = json.dumps({"$set": {"active": False}})
```

```python
res = storage.run(action="update", collection=collection, filter=filter, update=update, many=True)

if res["matchedCount"] != expected:
    print(f"expected {expected}, matched {res['matchedCount']}")
```
