Skip to content

API reference

update

Updates a document within a specified collection.

Parameters

PropTypeDescription
pathstringThe path to the document, which includes collection name and document ID.
dataanyThe new data to merge with the existing document.

Returns

  • Returns a promise that resolves to the updated document.

Example

js
const initialUser = await db.add("users", { name: "John Doe", age: 25 });
const updatedUser = await db.update(`users/${initialUser.id}`, { age: 30 });
console.log(updatedUser);
// Output: { id: "generated-id", createdAt: 1696872345000, name: "John Doe", age: 30 }

Released under the SSPL License.