DocumentReference class

ADocumentReference 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:

exportdeclareclassDocumentReference<AppModelType=DocumentData,DbModelTypeextendsDocumentData=DocumentData>

Properties

PropertyModifiersTypeDescription
converterFirestoreDataConverter<AppModelType, DbModelType> | nullIf provided, theFirestoreDataConverter associated with this instance.
firestoreFirestoreTheFirestore 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 thisDocumentReference 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.

Methods

MethodModifiersDescription
fromJSON(firestore, json)staticBuilds aDocumentReference instance from a JSON object created byDocumentReference.toJSON().
fromJSON(firestore, json, converter)staticBuilds aDocumentReference instance from a JSON object created byDocumentReference.toJSON().
toJSON()Returns a JSON-serializable representation of thisDocumentReference instance.
withConverter(converter)Applies a custom data converter to thisDocumentReference, allowing you to use your own custom model objects with Firestore. When you callsetDoc(),getDoc(), etc. with the returnedDocumentReference instance, the provided converter will convert between Firestore data of typeNewDbModelType and your custom typeNewAppModelType.
withConverter(converter)Removes the current converter.

DocumentReference.converter

If provided, theFirestoreDataConverter associated with this instance.

Signature:

readonlyconverter:FirestoreDataConverter<AppModelType,DbModelType>|null;

DocumentReference.firestore

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

Signature:

readonlyfirestore:Firestore;

DocumentReference.id

The document's identifier within its collection.

Signature:

getid():string;

DocumentReference.parent

The collection thisDocumentReference belongs to.

Signature:

getparent():CollectionReference<AppModelType,DbModelType>;

DocumentReference.path

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

Signature:

getpath():string;

DocumentReference.type

The type of this Firestore reference.

Signature:

readonlytype="document";

DocumentReference.fromJSON()

Builds aDocumentReference instance from a JSON object created byDocumentReference.toJSON().

Signature:

staticfromJSON(firestore:Firestore,json:object):DocumentReference;

Parameters

ParameterTypeDescription
firestoreFirestoreTheFirestore instance the snapshot should be loaded for.
jsonobjecta JSON object represention of aDocumentReference instance

Returns:

DocumentReference

an instance ofDocumentReference if the JSON object could be parsed. Throws aFirestoreError if an error occurs.

DocumentReference.fromJSON()

Builds aDocumentReference instance from a JSON object created byDocumentReference.toJSON().

Signature:

staticfromJSON<NewAppModelType=DocumentData,NewDbModelTypeextendsDocumentData=DocumentData>(firestore:Firestore,json:object,converter:FirestoreDataConverter<NewAppModelType,NewDbModelType>):DocumentReference<NewAppModelType,NewDbModelType>;

Parameters

ParameterTypeDescription
firestoreFirestoreTheFirestore instance the snapshot should be loaded for.
jsonobjecta JSON object represention of aDocumentReference instance
converterFirestoreDataConverter<NewAppModelType, NewDbModelType>Converts objects to and from Firestore.

Returns:

DocumentReference<NewAppModelType, NewDbModelType>

an instance ofDocumentReference if the JSON object could be parsed. Throws aFirestoreError if an error occurs.

DocumentReference.toJSON()

Returns a JSON-serializable representation of thisDocumentReference instance.

Signature:

toJSON():object;

Returns:

object

a JSON representation of this object.

DocumentReference.withConverter()

Applies a custom data converter to thisDocumentReference, allowing you to use your own custom model objects with Firestore. When you callsetDoc(),getDoc(), etc. with the returnedDocumentReference instance, the provided converter will convert between Firestore data of typeNewDbModelType and your custom typeNewAppModelType.

Signature:

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

Parameters

ParameterTypeDescription
converterFirestoreDataConverter<NewAppModelType, NewDbModelType>Converts objects to and from Firestore.

Returns:

DocumentReference<NewAppModelType, NewDbModelType>

ADocumentReference that uses the provided converter.

DocumentReference.withConverter()

Removes the current converter.

Signature:

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

Parameters

ParameterTypeDescription
converternullnull removes the current converter.

Returns:

DocumentReference<DocumentData,DocumentData>

ADocumentReference<DocumentData, DocumentData> that does not use a converter.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-06-30 UTC.