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 > / > addDoc

addDoc() function

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

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 (Note that it won't resolve while you're offline).