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.
update
update operation to run on disconnect. Only the specified children are modified; other children at this location are left intact.
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.
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.

