voluptasmollitia
Version:
Monorepo for the Firebase JavaScript SDK
40 lines (22 loc) • 1.71 kB
Markdown
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[](./index.md) > [@firebase/database](./database.md) > [set](./database.set.md)
Writes data to this Database location.
This will overwrite any data at this location and all child locations.
The effect of the write will be visible immediately, and the corresponding events ("value", "child\_added", etc.) will be triggered. Synchronization of the data to the Firebase servers will also be started, and the returned Promise will resolve when complete. If provided, the `onComplete` callback will be called asynchronously after synchronization has finished.
Passing `null` for the new value is equivalent to calling `remove()`<!-- -->; namely, all data at this location and all child locations will be deleted.
`set()` will remove any priority stored at this location, so if priority is meant to be preserved, you need to use `setWithPriority()` instead.
Note that modifying data with `set()` will cancel any pending transactions at that location, so extreme care should be taken if mixing `set()` and `transaction()` to modify the same data.
A single `set()` will generate a single "value" event at the location where the `set()` was performed.
<b>Signature:</b>
```typescript
export declare function set(ref: Reference, value: unknown): Promise<void>;
```
| Parameter | Type | Description |
| --- | --- | --- |
| ref | [Reference](./database.reference.md) | The location to write to. |
| value | unknown | The value to be written (string, number, boolean, object, array, or null). |
<b>Returns:</b>
Promise<void>
Resolves when write to server is complete.