DocumentReference class

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.

Signature:

export declare class DocumentReference<AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData> 

Properties

Property Modifiers Type Description
converter FirestoreDataConverter<AppModelType, DbModelType> | null If provided, the FirestoreDataConverter associated with this instance.
firestore Firestore The Firestore instance the document is in. This is useful for performing transactions, for example.
id string The document's identifier within its collection.
parent CollectionReference<AppModelType, DbModelType> The collection this DocumentReference belongs to.
path string A string representing the path of the referenced document (relative to the root of the database).
type (not declared) The type of this Firestore reference.

Methods

Method Modifiers Description
withConverter(converter) Applies a custom data converter to this DocumentReference, allowing you to use your own custom model objects with Firestore. When you call setDoc(), getDoc(), etc. with the returned DocumentReference instance, the provided converter will convert between Firestore data of type NewDbModelType and your custom type NewAppModelType.
withConverter(converter) Removes the current converter.

DocumentReference.converter

If provided, the FirestoreDataConverter associated with this instance.

Signature:

readonly converter: FirestoreDataConverter<AppModelType, DbModelType> | null;

DocumentReference.firestore

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

Signature:

readonly firestore: Firestore;

DocumentReference.id

The document's identifier within its collection.

Signature:

get id(): string;

DocumentReference.parent

The collection this DocumentReference belongs to.

Signature:

get parent(): CollectionReference<AppModelType, DbModelType>;

DocumentReference.path

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

Signature:

get path(): string;

DocumentReference.type

The type of this Firestore reference.

Signature:

readonly type = "document";

DocumentReference.withConverter()

Applies a custom data converter to this DocumentReference, allowing you to use your own custom model objects with Firestore. When you call setDoc(), getDoc(), etc. with the returned DocumentReference instance, the provided converter will convert between Firestore data of type NewDbModelType and your custom type NewAppModelType.

Signature:

withConverter<NewAppModelType, NewDbModelType extends DocumentData = DocumentData>(converter: FirestoreDataConverter<NewAppModelType, NewDbModelType>): DocumentReference<NewAppModelType, NewDbModelType>;

Parameters

Parameter Type Description
converter FirestoreDataConverter<NewAppModelType, NewDbModelType> Converts objects to and from Firestore.

Returns:

DocumentReference<NewAppModelType, NewDbModelType>

A DocumentReference that uses the provided converter.

DocumentReference.withConverter()

Removes the current converter.

Signature:

withConverter(converter: null): DocumentReference<DocumentData, DocumentData>;

Parameters

Parameter Type Description
converter null null removes the current converter.

Returns:

DocumentReference<DocumentData, DocumentData>

A DocumentReference<DocumentData, DocumentData> that does not use a converter.