OnDB uses append-only storage. Updates do NOT modify existing data. Instead, a NEW record with the same ID and a newer timestamp is appended. Queries automatically return the latest version of each record. Use queryBuilder().executeUnique() to get the latest version of a single record.
Original Record (Block 100):{ id: "user_1", name: "Alice", email: "alice@example.com", updatedAt: "2024-01-01" }After Update (Block 101):{ id: "user_1", name: "Alice Smith", email: "alice@example.com", updatedAt: "2024-01-02" }Both records are preserved, but queries return the latest version
Since updates append new records, you can query historical versions:
TypeScript
const allVersions = await client.queryBuilder() .collection('users') .whereField('id').equals('user_123') .includeHistory() .execute();// Sort by updatedAt to see historyconst history = allVersions.records.sort( (a, b) => new Date(a.updatedAt).getTime() - new Date(b.updatedAt).getTime());