The Firebase JS SDK is now in BETA!
This EAP site is no longer maintained. See the official Firebase Documentation site for the latest documentation and information about the Firebase JS SDK.

Home > @firebase/firestore > lite > addDoc

addDoc() function

Add a new document to specified CollectionReference with the given data, assigning it a document ID automatically.

The result of this write will only be reflected in document reads that occur after the returned Promise resolves. If the client is offline, the write fails. If you would like to see local modifications or buffer writes until the client is online, use the full Firestore SDK.

Signature:

export declare function addDoc<T>(reference: CollectionReference<T>, data: T): Promise<DocumentReference<T>>;

Parameters

Parameter Type Description
reference CollectionReference<T> A reference to the collection to add this document to.
data T An Object containing the data for the new document.

Returns:

Promise<DocumentReference<T>>

A Promise resolved with a DocumentReference pointing to the newly created document after it has been written to the backend.