Update Documents
Mission
Update operations allow developers to modify fields of existing documents. In both SDKs, fields to be updated are specified using the chainable `.set()` operator.
The Payoff
By completing this module, you will understand how to run merge modifications using direct record IDs, singular updates, and bulk query updates.
Estimated Time: 3 minutesModules: 3 Concepts
Merge Updates Behavior
Updates in Thinking Differently behave as merges. Only the fields specified in your `.set()` calls will be modified or added; other keys in the document payload remain unaffected.
Define field mutations
Chain the .set(key, value) operator for each parameter you intend to modify.
Submit updates using ID
Call .updateById('id') at the end of the chain to update that single record.
Interactive Code Snippet
typescript
const response = await sdk.collection("users") .set("status", "active") .set("verified", true) .updateById("user_12345");console.log("Update timestamp:", response.updatedAt);Select document filters
Apply selector criteria using .where(field, operator, value).
Set values and updateOne
Specify the properties using .set() and invoke .updateOne() to commit the single matched update.
Interactive Code Snippet
typescript
// Finds the first user with this email and updates their roleawait sdk.collection("users") .where("email", "=", "[email protected]") .set("role", "admin") .updateOne();Select bulk target scope
Use .where() query expressions to filter multiple target records.
Run updateMany
Declare values with .set() and run .updateMany() to modify all matching items at once.
Interactive Code Snippet
typescript
// Updates status for all users registered as guestawait sdk.collection("users") .where("role", "=", "guest") .set("status", "expired") .updateMany();