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> 
PropertyModifiersTypeDescription
converterFirestoreDataConverter<AppModelType, DbModelType> | nullIf provided, the FirestoreDataConverter associated with this instance.
firestoreFirestoreThe Firestore instance the document is in. This is useful for performing transactions, for example.
idstringThe document's identifier within its collection.
parentCollectionReference<AppModelType, DbModelType>The collection this DocumentReference belongs to.
pathstringA string representing the path of the referenced document (relative to the root of the database).
type(not declared)The type of this Firestore reference.
MethodModifiersDescription
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.

If provided, the FirestoreDataConverter associated with this instance.

Signature:

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

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

Signature:

readonly firestore: Firestore;

The document's identifier within its collection.

Signature:

get id(): string;

The collection this DocumentReference belongs to.

Signature:

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

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

Signature:

get path(): string;

The type of this Firestore reference.

Signature:

readonly type = "document";

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>;
ParameterTypeDescription
converterFirestoreDataConverter<NewAppModelType, NewDbModelType>Converts objects to and from Firestore.

Returns:

DocumentReference<NewAppModelType, NewDbModelType>

A DocumentReference that uses the provided converter.

Removes the current converter.

Signature:

withConverter(converter: null): DocumentReference<DocumentData, DocumentData>;
ParameterTypeDescription
converternullnull removes the current converter.

Returns:

DocumentReference<DocumentData, DocumentData>

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