TheDocumentation Index
Fetch the complete documentation index at: https://docs.larksh.com/llms.txt
Use this file to discover all available pages before exploring further.
OnDisconnect class lets you register write operations that the server will execute if the client disconnects unexpectedly. This is commonly used for presence systems, cleanup tasks, and ensuring data consistency when a user goes offline.
Obtain an OnDisconnect instance via DatabaseReference.onDisconnect().
All
OnDisconnect methods return a Promise that resolves once the server has acknowledged and registered the operation. The operation itself executes later, only if the client disconnects.Methods
set
set operation to run on disconnect. The specified value will replace any data at this location when the client disconnects.
| Parameter | Type | Description |
|---|---|---|
value | any | The value to write on disconnect. Pass null to delete the data. |
update
update operation to run on disconnect. Only the specified children are modified; other children at this location are left intact.
| Parameter | Type | Description |
|---|---|---|
values | object | An object containing the children to update on disconnect. |
remove
remove operation to run on disconnect. All data at this location (and its children) will be deleted when the client disconnects.
setWithPriority
set operation with a priority to run on disconnect.
| Parameter | Type | Description |
|---|---|---|
value | any | The value to write on disconnect. |
priority | string | number | null | The priority to assign. |
cancel
OnDisconnect operations at this location. The server will no longer perform any disconnect writes for this reference.
Usage Pattern
A typical presence system combinesonDisconnect with a normal write to track whether a user is online.

