Set
set overwrites the value at a path completely. Whatever was there before is gone, replaced by the new value.
set an object, it replaces the entire object at that path. If Alice had an online field before, it’s gone now, because the new object doesn’t include it.
Update
update performs a shallow merge at a path. It updates the keys you specify and leaves everything else untouched.
Multi-path atomic updates
update also supports atomic writes across multiple paths. Prefix keys with / to write to absolute paths in a single atomic operation:
Remove
remove deletes the data at a path. It’s equivalent to calling set with null.
Push
push generates a unique, chronologically sortable key and writes your data under it. This is perfect for lists where items are added over time: chat messages, event logs, game actions.
push() without any data to generate a key without writing anything yet. This is useful when you need the key upfront, for example to use it in a multi-path update:
Push keys contain a timestamp component plus randomness. They sort in chronological order, so querying with
orderByKey gives you messages in the order they were created.Once (read)
once reads the current value at a path and returns a snapshot. It’s a one-time read: unlike a subscription, it doesn’t listen for future changes.
val() to get the raw JSON value, exists() to check if there’s data there, and child() to navigate into nested values.
Server values
Sometimes you want the server to fill in a value rather than the client.ServerValue.TIMESTAMP is replaced by the server’s current time (in milliseconds since epoch) when the write is processed.
Date.now() on the client, every device’s clock would produce a slightly different value. With ServerValue.TIMESTAMP, every client agrees on the same time.
Server values are resolved on write. When you read the data back, you’ll see the actual timestamp number, not a placeholder.
Optimistic writes
When you write data, Lark applies the change to your local state immediately, before the server confirms it. Your UI updates instantly. Here’s the flow:- You call
set,update, orremove. - Lark applies the change locally right away. Any active subscriptions fire with the new data.
- The write is sent to the server.
- The server processes it (checking security rules, validating data).
- If the server accepts, nothing else happens. Your local state was already correct.
- If the server rejects (permissions, validation), Lark rolls back the local change and your subscriptions fire again with the corrected data.
What’s next
Sorting and filtering
Order results, filter with ranges, and paginate through data.
Subscriptions
Listen for real-time changes with event types and delta sync.
Transactions
Atomic read-modify-write operations for safe concurrent updates.
Security rules
Validate incoming writes and control access.

