voluptasmollitia
Version:
Monorepo for the Firebase JavaScript SDK
28 lines (16 loc) • 1.1 kB
Markdown
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) > [@firebase/firestore](./firestore.md) > [/](./firestore_.md) > [addDoc](./firestore_.adddoc.md)
## addDoc() function
Add a new document to specified `CollectionReference` with the given data, assigning it a document ID automatically.
<b>Signature:</b>
```typescript
export declare function addDoc<T>(reference: CollectionReference<T>, data: T): Promise<DocumentReference<T>>;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| reference | [CollectionReference](./firestore_.collectionreference.md)<!-- --><T> | A reference to the collection to add this document to. |
| data | T | An Object containing the data for the new document. |
<b>Returns:</b>
Promise<[DocumentReference](./firestore_.documentreference.md)<!-- --><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).