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

doc() function

Gets a DocumentReference instance that refers to a document within reference at the specified relative path. If no path is specified, an automatically-generated unique ID will be used for the returned DocumentReference.

Signature:

export declare function doc<T>(reference: CollectionReference<T>, path?: string, ...pathSegments: string[]): DocumentReference<T>;

Parameters

Parameter Type Description
reference CollectionReference<T> A reference to a collection.
path string A slash-separated path to a document. Has to be omitted to use auto-genrated IDs.
pathSegments string[] Additional path segments that will be applied relative to the first argument.

Returns:

DocumentReference<T>

The DocumentReference instance.

Exceptions

If the final path has an odd number of segments and does not point to a document.