RefirebaseRefirebase

add

Add a new document to a collection in Firestore.

Usage

Use db.firestore.add to add a new document. If you don't provide a docId, Firestore generates one for you. This method also automatically appends created_at and updated_at timestamps.

Add a new document
import { db } from 'refirebase';

const result = await db.firestore.add('users', {
  name: 'John Doe',
  age: 30
});

if ('error' in result) {
  console.error('Error adding document:', result.error);
} else {
  console.log('Added document with ID:', result.id);
}

Parameters

ParamTypeDescription
collectionName*stringThe name of the collection.
data*TThe data to store.
docIdstringAn optional ID for the document.

Return value

Returns

Promise<ReturnGenericObj<T> | FirestoreError>

Returns the inserted document data (including its generated ID), or an error object if the operation fails.