A CollectionReference object can be used for adding documents, getting document references, and querying for documents (using the methods inherited from [Query]Query).
CollectionReference Query
Package
@google-cloud/firestore!Constructors
(constructor)(firestore, path, converter)
constructor(firestore: Firestore, path: ResourcePath, converter?: firestore.FirestoreDataConverter<T>);
Constructs a new instance of the CollectionReference
class
Name | Description |
firestore |
Firestore
The Firestore Database client. |
path |
ResourcePath
The Path of this collection. |
converter |
FirebaseFirestore.FirestoreDataConverter<T>
|
Properties
_resourcePath
get _resourcePath(): ResourcePath;
Returns a resource path for this collection.
Type | Description |
ResourcePath |
id
get id(): string;
The last path element of the referenced collection.
{string} CollectionReference#id
Type | Description |
string |
parent
get parent(): DocumentReference<firestore.DocumentData> | null;
A reference to the containing Document if this is a subcollection, else null.
{DocumentReference|null} CollectionReference#parent
Type | Description |
DocumentReference<FirebaseFirestore.DocumentData> | null |
path
get path(): string;
A string representing the path of the referenced collection (relative to the root of the database).
{string} CollectionReference#path
Type | Description |
string |
Methods
add(data)
add(data: T): Promise<DocumentReference<T>>;
Add a new document to this collection with the specified data, assigning it a document ID automatically.
Name | Description |
data |
T
An Object containing the data for the new document. |
Type | Description |
Promise<DocumentReference<T>> | {Promise.
|
doc()
doc(): DocumentReference<T>;
Type | Description |
DocumentReference<T> |
doc(documentPath)
doc(documentPath: string): DocumentReference<T>;
Name | Description |
documentPath |
string
|
Type | Description |
DocumentReference<T> |
isEqual(other)
isEqual(other: firestore.CollectionReference<T>): boolean;
Returns true if this CollectionReference
is equal to the provided value.
Name | Description |
other |
FirebaseFirestore.CollectionReference<T>
The value to compare against. {boolean} true if this |
Type | Description |
boolean |
listDocuments()
listDocuments(): Promise<Array<DocumentReference<T>>>;
Retrieves the list of documents in this collection.
The document references returned may include references to "missing documents", i.e. document locations that have no document present but which contain subcollections with documents. Attempting to read such a document reference (e.g. via .get()
or .onSnapshot()
) will return a DocumentSnapshot
whose .exists
property is false.
{Promise<DocumentReference[]>} The list of documents in this collection.
Type | Description |
Promise<Array<DocumentReference<T>>> |
withConverter(converter)
withConverter(converter: null): CollectionReference<firestore.DocumentData>;
Applies a custom data converter to this CollectionReference, allowing you to use your own custom model objects with Firestore. When you call add() on the returned CollectionReference instance, the provided converter will convert between Firestore data and your custom type U.
Using the converter allows you to specify generic type arguments when storing and retrieving objects from Firestore.
Passing in null
as the converter parameter removes the current converter.
Name | Description |
converter |
null
Converts objects to and from Firestore. Passing in
|
Type | Description |
CollectionReference<FirebaseFirestore.DocumentData> |
withConverter(converter)
withConverter<U>(converter: firestore.FirestoreDataConverter<U>): CollectionReference<U>;
Name | Description |
converter |
FirebaseFirestore.FirestoreDataConverter<U>
|
Type | Description |
CollectionReference<U> |
Name | Description |
U |