Jump to top

DocumentReference

interface

A DocumentReference refers to a document location in a Firestore database and can be used to write, read, or listen to the location. The document at the referenced location may or may not exist. A DocumentReference can also be used to create a CollectionReference to a subcollection.

Properties

firestore

</>

The Firestore instance the document is in. This is useful for performing transactions, for example.

firestore: Module;

id

</>

The document's identifier within its collection.

id: string;

parent

</>

The Collection this DocumentReference belongs to.

path

</>

A string representing the path of the referenced document (relative to the root of the database).

path: string;

Methods

collection

</>

Gets a CollectionReference instance that refers to the collection at the specified path.

collection(collectionPath: string): CollectionReference;

delete

</>

Deletes the document referred to by this DocumentReference.

delete(): Promise<void>;

get

</>

Reads the document referred to by this DocumentReference.

isEqual

</>

Returns true if this DocumentReference is equal to the provided one.

isEqual(other: DocumentReference): boolean;

onSnapshot

</>
Signature 1
</>

Attaches a listener for DocumentSnapshot events.

onSnapshot(observer: { complete: undefined | () => void, error: undefined | (error: Error) => void, next: undefined | (snapshot: DocumentSnapshot) => void }): () => void;
Signature 2
</>

Attaches a listener for DocumentSnapshot events with snapshot listener options.

onSnapshot(options: SnapshotListenOptions, observer: { complete: undefined | () => void, error: undefined | (error: Error) => void, next: undefined | (snapshot: DocumentSnapshot) => void }): () => void;
Signature 3
</>

Attaches a listener for DocumentSnapshot events.

onSnapshot(onNext: (snapshot: DocumentSnapshot) => void, onError?: undefined | (error: Error) => void, onCompletion?: undefined | () => void): () => void;
Signature 4
</>

Attaches a listener for DocumentSnapshot events with snapshot listener options.

onSnapshot(options: SnapshotListenOptions, onNext: (snapshot: DocumentSnapshot) => void, onError?: undefined | (error: Error) => void, onCompletion?: undefined | () => void): () => void;

set

</>

Writes to the document referred to by this DocumentReference. If the document does not yet exist, it will be created. If you pass SetOptions, the provided data can be merged into an existing document.

set(data: { [key: string]: value }, options?: SetOptions): Promise<void>;

update

</>
Signature 1
</>

Updates fields in the document referred to by this DocumentReference. The update will fail if applied to a document that does not exist.

update(data: { [key: string]: value }): Promise<void>;
Signature 2
</>

Updates fields in the document referred to by this DocumentReference. The update will fail if applied to a document that does not exist.

update(field: string | FieldPath, value: any, moreFieldsAndValues: any[]): Promise<void>;