Project: /docs/reference/js/_project.yaml
Book: /docs/reference/_book.yaml
page_type: reference
{% comment %}
DO NOT EDIT THIS FILE!
This is generated by the JS SDK team, and any local changes will be
overwritten. Changes should be made in the source code at
https://github.com/firebase/firebase-js-sdk
{% endcomment %}
# 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:
```typescript
export declare class DocumentReference
```
## Properties
| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [converter](./firestore_lite.documentreference.md#documentreferenceconverter) | | [FirestoreDataConverter](./firestore_lite.firestoredataconverter.md#firestoredataconverter_interface)<AppModelType, DbModelType> \| null | If provided, the FirestoreDataConverter associated with this instance. |
| [firestore](./firestore_lite.documentreference.md#documentreferencefirestore) | | [Firestore](./firestore_lite.firestore.md#firestore_class) | The [Firestore](./firestore_.firestore.md#firestore_class) instance the document is in. This is useful for performing transactions, for example. |
| [id](./firestore_lite.documentreference.md#documentreferenceid) | | string | The document's identifier within its collection. |
| [parent](./firestore_lite.documentreference.md#documentreferenceparent) | | [CollectionReference](./firestore_lite.collectionreference.md#collectionreference_class)<AppModelType, DbModelType> | The collection this DocumentReference belongs to. |
| [path](./firestore_lite.documentreference.md#documentreferencepath) | | string | A string representing the path of the referenced document (relative to the root of the database). |
| [type](./firestore_lite.documentreference.md#documentreferencetype) | | (not declared) | The type of this Firestore reference. |
## Methods
| Method | Modifiers | Description |
| --- | --- | --- |
| [fromJSON(firestore, json)](./firestore_lite.documentreference.md#documentreferencefromjson) | static | Builds a DocumentReference instance from a JSON object created by [DocumentReference.toJSON()](./firestore_.documentreference.md#documentreferencetojson). |
| [fromJSON(firestore, json, converter)](./firestore_lite.documentreference.md#documentreferencefromjson) | static | Builds a DocumentReference instance from a JSON object created by [DocumentReference.toJSON()](./firestore_.documentreference.md#documentreferencetojson). |
| [toJSON()](./firestore_lite.documentreference.md#documentreferencetojson) | | Returns a JSON-serializable representation of this DocumentReference instance. |
| [withConverter(converter)](./firestore_lite.documentreference.md#documentreferencewithconverter) | | Applies a custom data converter to this DocumentReference, allowing you to use your own custom model objects with Firestore. When you call [setDoc()](./firestore_lite.md#setdoc_ee215ad), [getDoc()](./firestore_lite.md#getdoc_4569087), etc. with the returned DocumentReference instance, the provided converter will convert between Firestore data of type NewDbModelType and your custom type NewAppModelType. |
| [withConverter(converter)](./firestore_lite.documentreference.md#documentreferencewithconverter) | | Removes the current converter. |
## DocumentReference.converter
If provided, the `FirestoreDataConverter` associated with this instance.
Signature:
```typescript
readonly converter: FirestoreDataConverter | null;
```
## DocumentReference.firestore
The [Firestore](./firestore_.firestore.md#firestore_class) instance the document is in. This is useful for performing transactions, for example.
Signature:
```typescript
readonly firestore: Firestore;
```
## DocumentReference.id
The document's identifier within its collection.
Signature:
```typescript
get id(): string;
```
## DocumentReference.parent
The collection this `DocumentReference` belongs to.
Signature:
```typescript
get parent(): CollectionReference;
```
## DocumentReference.path
A string representing the path of the referenced document (relative to the root of the database).
Signature:
```typescript
get path(): string;
```
## DocumentReference.type
The type of this Firestore reference.
Signature:
```typescript
readonly type = "document";
```
## DocumentReference.fromJSON()
Builds a `DocumentReference` instance from a JSON object created by [DocumentReference.toJSON()](./firestore_.documentreference.md#documentreferencetojson).
Signature:
```typescript
static fromJSON(firestore: Firestore, json: object): DocumentReference;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| firestore | [Firestore](./firestore_lite.firestore.md#firestore_class) | The [Firestore](./firestore_.firestore.md#firestore_class) instance the snapshot should be loaded for. |
| json | object | a JSON object represention of a DocumentReference instance |
Returns:
[DocumentReference](./firestore_lite.documentreference.md#documentreference_class)
an instance of [DocumentReference](./firestore_.documentreference.md#documentreference_class) if the JSON object could be parsed. Throws a [FirestoreError](./firestore_.firestoreerror.md#firestoreerror_class) if an error occurs.
## DocumentReference.fromJSON()
Builds a `DocumentReference` instance from a JSON object created by [DocumentReference.toJSON()](./firestore_.documentreference.md#documentreferencetojson).
Signature:
```typescript
static fromJSON(firestore: Firestore, json: object, converter: FirestoreDataConverter): DocumentReference;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| firestore | [Firestore](./firestore_lite.firestore.md#firestore_class) | The [Firestore](./firestore_.firestore.md#firestore_class) instance the snapshot should be loaded for. |
| json | object | a JSON object represention of a DocumentReference instance |
| converter | [FirestoreDataConverter](./firestore_lite.firestoredataconverter.md#firestoredataconverter_interface)<NewAppModelType, NewDbModelType> | Converts objects to and from Firestore. |
Returns:
[DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<NewAppModelType, NewDbModelType>
an instance of [DocumentReference](./firestore_.documentreference.md#documentreference_class) if the JSON object could be parsed. Throws a [FirestoreError](./firestore_.firestoreerror.md#firestoreerror_class) if an error occurs.
## DocumentReference.toJSON()
Returns a JSON-serializable representation of this `DocumentReference` instance.
Signature:
```typescript
toJSON(): object;
```
Returns:
object
a JSON representation of this object.
## 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()](./firestore_lite.md#setdoc_ee215ad), [getDoc()](./firestore_lite.md#getdoc_4569087), etc. with the returned `DocumentReference` instance, the provided converter will convert between Firestore data of type `NewDbModelType` and your custom type `NewAppModelType`.
Signature:
```typescript
withConverter(converter: FirestoreDataConverter): DocumentReference;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| converter | [FirestoreDataConverter](./firestore_lite.firestoredataconverter.md#firestoredataconverter_interface)<NewAppModelType, NewDbModelType> | Converts objects to and from Firestore. |
Returns:
[DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<NewAppModelType, NewDbModelType>
A `DocumentReference` that uses the provided converter.
## DocumentReference.withConverter()
Removes the current converter.
Signature:
```typescript
withConverter(converter: null): DocumentReference;
```
#### Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| converter | null | null removes the current converter. |
Returns:
[DocumentReference](./firestore_lite.documentreference.md#documentreference_class)<[DocumentData](./firestore_lite.documentdata.md#documentdata_interface), [DocumentData](./firestore_lite.documentdata.md#documentdata_interface)>
A `DocumentReference` that does not use a converter.