Type parameters
-
T
Index
Constructors
Properties
Methods
Constructors
Private constructor
-
Returns DocumentReference
Properties
firestore
The firebase.firestore.Firestore the document is in. This is useful for performing transactions, for example.
id
The document's identifier within its collection.
parent
The Collection this DocumentReference
belongs to.
path
A string representing the path of the referenced document (relative to the root of the database).
Methods
collection
-
Gets a
CollectionReference
instance that refers to the collection at the specified path.Parameters
-
collectionPath: string
A slash-separated path to a collection.
Returns CollectionReference<DocumentData>
The
CollectionReference
instance. -
delete
-
Deletes the document referred to by this
DocumentReference
.Returns Promise<void>
A Promise resolved once the document has been successfully deleted from the backend (Note that it won't resolve while you're offline).
get
-
Reads the document referred to by this
DocumentReference
.Note: By default, get() attempts to provide up-to-date data when possible by waiting for data from the server, but it may return cached data or fail if you are offline and the server cannot be reached. This behavior can be altered via the
GetOptions
parameter.Parameters
-
Optional options: GetOptions
An object to configure the get behavior.
Returns Promise<DocumentSnapshot<T>>
A Promise resolved with a DocumentSnapshot containing the current document contents.
-
isEqual
-
Returns true if this
DocumentReference
is equal to the provided one.Parameters
-
other: DocumentReference<T>
The
DocumentReference
to compare against.
Returns boolean
true if this
DocumentReference
is equal to the provided one. -
onSnapshot
-
Attaches a listener for DocumentSnapshot events. You may either pass individual
onNext
andonError
callbacks or pass a single observer object withnext
anderror
callbacks.NOTE: Although an
onCompletion
callback can be provided, it will never be called because the snapshot stream is never-ending.Parameters
-
observer: { complete?: () => void; error?: (error: FirestoreError) => void; next?: (snapshot: DocumentSnapshot<T>) => void }
A single object containing
next
anderror
callbacks.-
Optional complete?: () => void
-
-
Returns void
-
-
-
Optional error?: (error: FirestoreError) => void
-
-
Parameters
-
error: FirestoreError
Returns void
-
-
-
-
Optional next?: (snapshot: DocumentSnapshot<T>) => void
-
-
Parameters
-
snapshot: DocumentSnapshot<T>
Returns void
-
-
-
-
Returns () => void
An unsubscribe function that can be called to cancel the snapshot listener.
-
-
Returns void
-
-
-
Attaches a listener for DocumentSnapshot events. You may either pass individual
onNext
andonError
callbacks or pass a single observer object withnext
anderror
callbacks.NOTE: Although an
onCompletion
callback can be provided, it will never be called because the snapshot stream is never-ending.Parameters
-
options: SnapshotListenOptions
Options controlling the listen behavior.
-
observer: { complete?: () => void; error?: (error: FirestoreError) => void; next?: (snapshot: DocumentSnapshot<T>) => void }
A single object containing
next
anderror
callbacks.-
Optional complete?: () => void
-
-
Returns void
-
-
-
Optional error?: (error: FirestoreError) => void
-
-
Parameters
-
error: FirestoreError
Returns void
-
-
-
-
Optional next?: (snapshot: DocumentSnapshot<T>) => void
-
-
Parameters
-
snapshot: DocumentSnapshot<T>
Returns void
-
-
-
-
Returns () => void
An unsubscribe function that can be called to cancel the snapshot listener.
-
-
Returns void
-
-
-
Attaches a listener for DocumentSnapshot events. You may either pass individual
onNext
andonError
callbacks or pass a single observer object withnext
anderror
callbacks.NOTE: Although an
onCompletion
callback can be provided, it will never be called because the snapshot stream is never-ending.Parameters
-
onNext: (snapshot: DocumentSnapshot<T>) => void
A callback to be called every time a new
DocumentSnapshot
is available.-
-
Parameters
-
snapshot: DocumentSnapshot<T>
Returns void
-
-
-
-
Optional onError: (error: FirestoreError) => void
A callback to be called if the listen fails or is cancelled. No further callbacks will occur.
-
-
Parameters
-
error: FirestoreError
Returns void
-
-
-
-
Optional onCompletion: () => void
-
-
Returns void
-
-
Returns () => void
An unsubscribe function that can be called to cancel the snapshot listener.
-
-
Returns void
-
-
-
Attaches a listener for DocumentSnapshot events. You may either pass individual
onNext
andonError
callbacks or pass a single observer object withnext
anderror
callbacks.NOTE: Although an
onCompletion
callback can be provided, it will never be called because the snapshot stream is never-ending.Parameters
-
options: SnapshotListenOptions
Options controlling the listen behavior.
-
onNext: (snapshot: DocumentSnapshot<T>) => void
A callback to be called every time a new
DocumentSnapshot
is available.-
-
Parameters
-
snapshot: DocumentSnapshot<T>
Returns void
-
-
-
-
Optional onError: (error: FirestoreError) => void
A callback to be called if the listen fails or is cancelled. No further callbacks will occur.
-
-
Parameters
-
error: FirestoreError
Returns void
-
-
-
-
Optional onCompletion: () => void
-
-
Returns void
-
-
Returns () => void
An unsubscribe function that can be called to cancel the snapshot listener.
-
-
Returns void
-
-
set
-
Writes to the document referred to by this
DocumentReference
. If the document does not yet exist, it will be created. If you passSetOptions
, the provided data can be merged into an existing document.Parameters
-
data: Partial<T>
A map of the fields and values for the document.
-
options: SetOptions
An object to configure the set behavior.
Returns Promise<void>
A Promise resolved once the data has been successfully written to the backend (Note that it won't resolve while you're offline).
-
-
Writes to the document referred to by this
DocumentReference
. If the document does not yet exist, it will be created. If you passSetOptions
, the provided data can be merged into an existing document.Parameters
-
data: T
A map of the fields and values for the document.
Returns Promise<void>
A Promise resolved once the data has been successfully written to the backend (Note that it won't resolve while you're offline).
-
update
-
Updates fields in the document referred to by this
DocumentReference
. The update will fail if applied to a document that does not exist.Parameters
-
data: UpdateData
An object containing the fields and values with which to update the document. Fields can contain dots to reference nested fields within the document.
Returns Promise<void>
A Promise resolved once the data has been successfully written to the backend (Note that it won't resolve while you're offline).
-
-
Updates fields in the document referred to by this
DocumentReference
. The update will fail if applied to a document that does not exist.Nested fields can be updated by providing dot-separated field path strings or by providing FieldPath objects.
Parameters
-
field: string | FieldPath
The first field to update.
-
value: any
The first value.
-
Rest ...moreFieldsAndValues: any[]
Additional key value pairs.
Returns Promise<void>
A Promise resolved once the data has been successfully written to the backend (Note that it won't resolve while you're offline).
-
withConverter
-
Applies a custom data converter to this DocumentReference, allowing you to use your own custom model objects with Firestore. When you call set(), get(), etc. on the returned DocumentReference instance, the provided converter will convert between Firestore data and your custom type U.
Passing in
null
as the converter parameter removes the current converter.Parameters
-
converter: null
Converts objects to and from Firestore. Passing in
null
removes the current converter.
Returns DocumentReference<DocumentData>
A DocumentReference that uses the provided converter.
-
-
Applies a custom data converter to this DocumentReference, allowing you to use your own custom model objects with Firestore. When you call set(), get(), etc. on the returned DocumentReference instance, the provided converter will convert between Firestore data and your custom type U.
Passing in
null
as the converter parameter removes the current converter.Type parameters
-
U
Parameters
-
converter: FirestoreDataConverter<U>
Converts objects to and from Firestore. Passing in
null
removes the current converter.
Returns DocumentReference<U>
A DocumentReference that uses the provided converter.
-
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. ADocumentReference
can also be used to create aCollectionReference
to a subcollection.