Back to Firebase Js Sdk

CollectionReference class

docs-devsite/firestore_lite.collectionreference.md

12.12.15.0 KB
Original Source

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 %}

CollectionReference class

A CollectionReference object can be used for adding documents, getting document references, and querying for documents (using query()<!-- -->).

<b>Signature:</b>

typescript
export declare class CollectionReference<AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData> extends Query<AppModelType, DbModelType> 

<b>Extends:</b> Query<!-- --><AppModelType, DbModelType>

Properties

PropertyModifiersTypeDescription
idstringThe collection's identifier.
parentDocumentReference<!-- --><DocumentData<!-- -->, DocumentData<!-- -->> | nullA reference to the containing <code>DocumentReference</code> if this is a subcollection. If this isn't a subcollection, the reference is null.
pathstringA string representing the path of the referenced collection (relative to the root of the database).
type(not declared)The type of this Firestore reference.

Methods

MethodModifiersDescription
withConverter(converter)Applies a custom data converter to this <code>CollectionReference</code>, allowing you to use your own custom model objects with Firestore. When you call addDoc() with the returned <code>CollectionReference</code> instance, the provided converter will convert between Firestore data of type <code>NewDbModelType</code> and your custom type <code>NewAppModelType</code>.
withConverter(converter)Removes the current converter.

CollectionReference.id

The collection's identifier.

<b>Signature:</b>

typescript
get id(): string;

CollectionReference.parent

A reference to the containing DocumentReference if this is a subcollection. If this isn't a subcollection, the reference is null.

<b>Signature:</b>

typescript
get parent(): DocumentReference<DocumentData, DocumentData> | null;

CollectionReference.path

A string representing the path of the referenced collection (relative to the root of the database).

<b>Signature:</b>

typescript
get path(): string;

CollectionReference.type

The type of this Firestore reference.

<b>Signature:</b>

typescript
readonly type = "collection";

CollectionReference.withConverter()

Applies a custom data converter to this CollectionReference<!-- -->, allowing you to use your own custom model objects with Firestore. When you call addDoc() with the returned CollectionReference instance, the provided converter will convert between Firestore data of type NewDbModelType and your custom type NewAppModelType<!-- -->.

<b>Signature:</b>

typescript
withConverter<NewAppModelType, NewDbModelType extends DocumentData = DocumentData>(converter: FirestoreDataConverter<NewAppModelType, NewDbModelType>): CollectionReference<NewAppModelType, NewDbModelType>;

Parameters

ParameterTypeDescription
converterFirestoreDataConverter<!-- --><NewAppModelType, NewDbModelType>Converts objects to and from Firestore.

<b>Returns:</b>

CollectionReference<!-- --><NewAppModelType, NewDbModelType>

A CollectionReference that uses the provided converter.

CollectionReference.withConverter()

Removes the current converter.

<b>Signature:</b>

typescript
withConverter(converter: null): CollectionReference<DocumentData, DocumentData>;

Parameters

ParameterTypeDescription
converternull<code>null</code> removes the current converter.

<b>Returns:</b>

CollectionReference<!-- --><DocumentData<!-- -->, DocumentData<!-- -->>

A CollectionReference<DocumentData, DocumentData> that does not use a converter.