DocumentReference class Stay organized with collections Save and categorize content based on your preferences.
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
| Property | Modifiers | Type | Description |
|---|---|---|---|
| converter | FirestoreDataConverter<AppModelType, DbModelType> | null | If provided, theFirestoreDataConverter associated with this instance. | |
| firestore | Firestore | TheFirestore 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 thisDocumentReference 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 |
|---|---|---|
| fromJSON(firestore, json) | static | Builds aDocumentReference instance from a JSON object created byDocumentReference.toJSON(). |
| fromJSON(firestore, json, converter) | static | Builds 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
| Parameter | Type | Description |
|---|---|---|
| firestore | Firestore | TheFirestore instance the snapshot should be loaded for. |
| json | object | a JSON object represention of aDocumentReference instance |
Returns:
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
| Parameter | Type | Description |
|---|---|---|
| firestore | Firestore | TheFirestore instance the snapshot should be loaded for. |
| json | object | a JSON object represention of aDocumentReference instance |
| converter | FirestoreDataConverter<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
| Parameter | Type | Description |
|---|---|---|
| converter | FirestoreDataConverter<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
| Parameter | Type | Description |
|---|---|---|
| converter | null | null 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.