RefirebaseRefirebase

set

Write data to a specific document, overwriting it if it already exists.

Usage

Use db.firestore.set to overwrite a document entirely or create a new one with a specific ID. It automatically updates the updated_at timestamp.

Set document data
import { db } from 'refirebase';

const result = await db.firestore.set('users', 'user-123', {
  name: 'Jane Doe',
  age: 28
});

if (result?.error) {
  console.error('Error setting document:', result.error);
} else {
  console.log('Document successfully set!');
}

Parameters

ParamTypeDescription
collectionName*stringThe name of the collection.
docId*stringThe ID of the document to write.
data*TThe data to set.

Return value

Returns

Promise<undefined | FirestoreError>

Returns undefined on success, or an error object on failure.