Back to Firebase Js Sdk

Query class

docs-devsite/firestore_lite.query.md

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

Query class

A Query refers to a query which you can read or listen to. You can also construct refined Query objects by adding filters and ordering.

<b>Signature:</b>

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

Constructors

ConstructorModifiersDescription
(constructor)()Constructs a new instance of the <code>Query</code> class

Properties

PropertyModifiersTypeDescription
converterFirestoreDataConverter<!-- --><AppModelType, DbModelType> | nullIf provided, the <code>FirestoreDataConverter</code> associated with this instance.
firestoreFirestoreThe <code>Firestore</code> instance for the Firestore database (useful for performing transactions, etc.).
type'query' | 'collection'The type of this Firestore reference.

Methods

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

Query.(constructor)

Constructs a new instance of the Query class

<b>Signature:</b>

typescript
protected constructor();

Query.converter

If provided, the FirestoreDataConverter associated with this instance.

<b>Signature:</b>

typescript
readonly converter: FirestoreDataConverter<AppModelType, DbModelType> | null;

Query.firestore

The Firestore instance for the Firestore database (useful for performing transactions, etc.).

<b>Signature:</b>

typescript
readonly firestore: Firestore;

Query.type

The type of this Firestore reference.

<b>Signature:</b>

typescript
readonly type: 'query' | 'collection';

Query.withConverter()

Removes the current converter.

<b>Signature:</b>

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

Parameters

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

<b>Returns:</b>

Query<!-- --><DocumentData<!-- -->, DocumentData<!-- -->>

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

Query.withConverter()

Applies a custom data converter to this query, allowing you to use your own custom model objects with Firestore. When you call getDocs() with the returned query, 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>): Query<NewAppModelType, NewDbModelType>;

Parameters

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

<b>Returns:</b>

Query<!-- --><NewAppModelType, NewDbModelType>

A Query that uses the provided converter.