Stay organized with collections Save and categorize content based on your preferences.
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
InheritanceQuery<AppModelType, DbModelType> > CollectionReference Package@google-cloud/firestore Constructors (constructor)(firestore, path, converter)constructor(firestore: Firestore, path: ResourcePath, converter?: firestore.FirestoreDataConverter<AppModelType, DbModelType>);
Constructs a new instance of the CollectionReference
class
firestore
Firestore
The Firestore Database client.
path
ResourcePath
The Path of this collection.
converter
FirebaseFirestore.FirestoreDataConverter<AppModelType, DbModelType>
The last path element of the referenced collection.
{string} CollectionReference#id
Example
let collectionRef = firestore.collection('col/doc/subcollection');
console.log(`ID of the subcollection: ${collectionRef.id}`);
parent
get parent(): DocumentReference | null;
A reference to the containing Document if this is a subcollection, else null.
{DocumentReference|null} CollectionReference#parent
Example
let collectionRef = firestore.collection('col/doc/subcollection');
let documentRef = collectionRef.parent;
console.log(`Parent name: ${documentRef.path}`);
path
A string representing the path of the referenced collection (relative to the root of the database).
{string} CollectionReference#path
Example
let collectionRef = firestore.collection('col/doc/subcollection');
console.log(`Path of the subcollection: ${collectionRef.path}`);
Methods add(data)
add(data: firestore.WithFieldValue<AppModelType>): Promise<DocumentReference<AppModelType, DbModelType>>;
Add a new document to this collection with the specified data, assigning it a document ID automatically.
Parameter Name Descriptiondata
FirebaseFirestore.WithFieldValue<AppModelType>
An Object containing the data for the new document.
Returns Type DescriptionPromise<DocumentReference<AppModelType, DbModelType>>
{Promise.
Example
let collectionRef = firestore.collection('col');
collectionRef.add({foo: 'bar'}).then(documentReference => {
console.log(`Added document with name: ${documentReference.id}`);
});
doc()
doc(): DocumentReference<AppModelType, DbModelType>;
doc(documentPath)
doc(documentPath: string): DocumentReference<AppModelType, DbModelType>;
Parameter Name Description documentPath
string
isEqual(other: firestore.CollectionReference<AppModelType, DbModelType>): boolean;
Returns true if this CollectionReference
is equal to the provided value.
other
FirebaseFirestore.CollectionReference<AppModelType, DbModelType>
The value to compare against. {boolean} true if this CollectionReference
is equal to the provided value.
boolean
listDocuments()
listDocuments(): Promise<Array<DocumentReference<AppModelType, DbModelType>>>;
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.
Returns Type DescriptionPromise<Array<DocumentReference<AppModelType, DbModelType>>>
Example
let collectionRef = firestore.collection('col');
return collectionRef.listDocuments().then(documentRefs => {
return firestore.getAll(...documentRefs);
}).then(documentSnapshots => {
for (let documentSnapshot of documentSnapshots) {
if (documentSnapshot.exists) {
console.log(`Found document with data: ${documentSnapshot.id}`);
} else {
console.log(`Found missing document: ${documentSnapshot.id}`);
}
}
});
withConverter(converter)
withConverter(converter: null): CollectionReference;
Parameter Name Description converter
null
withConverter<NewAppModelType, NewDbModelType extends firestore.DocumentData = firestore.DocumentData>(converter: firestore.FirestoreDataConverter<NewAppModelType, NewDbModelType>): CollectionReference<NewAppModelType, NewDbModelType>;
Parameter Name Description converter
FirebaseFirestore.FirestoreDataConverter<NewAppModelType, NewDbModelType>
NewAppModelType
NewDbModelType
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-07 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4