Skip to main content

Class: QueryBuilder<DocumentType>

A query builder that can be used to build a query that returns a list of documents.

Type parameters

NameType
DocumentTypeextends DocumentData

Hierarchy

Implements

Accessors

hash

get hash(): string

A unique hash for the query. Identical queries should return the same hash value.

Returns

string

The query's hash string.

Methods

addCompositeCondition

addCompositeCondition(conditions): QueryBuilder<DocumentType>

Parameters

NameType
conditionsSimpleCondition<any, string, Operator>[]

Returns

QueryBuilder<DocumentType>

Implementation of

SnapshotEmitter.addCompositeCondition


arrayIncludesAll

arrayIncludesAll(fieldName, values): QueryBuilder<DocumentType>

Adds a condition to the query to check if the specified field includes all the given values.

Parameters

NameTypeDescription
fieldNamestring | keyof DocumentType & stringThe name of the field to query.
valuesPrimitiveFieldType[]The values to check for inclusion in the field array.

Returns

QueryBuilder<DocumentType>

The query builder.

Inherited from

BaseQueryBuilder.arrayIncludesAll


arrayIncludesSome

arrayIncludesSome(fieldName, values): QueryBuilder<DocumentType>

Adds a condition to the query to check if the specified field includes any of the given values.

Parameters

NameTypeDescription
fieldNamestring | keyof DocumentType & stringThe name of the field to query.
valuesPrimitiveFieldType[]The values to check for inclusion in the field array.

Returns

QueryBuilder<DocumentType>

The query builder.

Inherited from

BaseQueryBuilder.arrayIncludesSome


arrayNotIncludes

arrayNotIncludes(fieldName, values): QueryBuilder<DocumentType>

Adds a condition to the query to check if the specified field does not include any of the given values.

Parameters

NameTypeDescription
fieldNamestring | keyof DocumentType & stringThe name of the field to query.
valuesPrimitiveFieldType[]The values to check for non-inclusion in the field array.

Returns

QueryBuilder<DocumentType>

The query builder.

Inherited from

BaseQueryBuilder.arrayNotIncludes


changes

changes(): Observable<Changes<DocumentType>>

Returns

Observable<Changes<DocumentType>>

Inherit Doc


clone

clone(): QueryBuilder<DocumentType>

Returns

QueryBuilder<DocumentType>

Implementation of

SnapshotEmitter.clone


dereference

dereference(): SnapshotEmitter<DocumentType>

Dereferences the document references in the result of this query. For example, collection.query().snapshot() returns an array of DocumentReference objects, but collection.query().dereference().snapshot() returns an array of the actual document data.

Returns

SnapshotEmitter<DocumentType>

Implementation of

HasDereference.dereference


eq

eq(fieldName, value): QueryBuilder<DocumentType>

A shortcut for where(fieldName, '==', value)

Parameters

NameTypeDescription
fieldNamestring | keyof DocumentType & stringThe name of the field to query.
valuePrimitiveFieldTypeThe value to compare against.

Returns

QueryBuilder<DocumentType>

The query builder.

Inherited from

BaseQueryBuilder.eq


flipSortOrder

flipSortOrder(): QueryBuilder<DocumentType>

Returns

QueryBuilder<DocumentType>

Implementation of

SnapshotEmitter.flipSortOrder


getLimit

getLimit(): number

Returns

number

Implementation of

SnapshotEmitter.getLimit


getSortOrder

getSortOrder(): FieldSort<DocumentType>[]

Returns

FieldSort<DocumentType>[]


getSortOrders

getSortOrders(): FieldSort<any>[]

Returns

FieldSort<any>[]

Implementation of

SnapshotEmitter.getSortOrders


gt

gt(fieldName, value): QueryBuilder<DocumentType>

A shortcut for where(fieldName, '>', value)

Parameters

NameTypeDescription
fieldNamestring | keyof DocumentType & stringThe name of the field to query.
valuePrimitiveFieldTypeThe value to compare against.

Returns

QueryBuilder<DocumentType>

The query builder.

Inherited from

BaseQueryBuilder.gt


gte

gte(fieldName, value): QueryBuilder<DocumentType>

A shortcut for where(fieldName, '>=', value)

Parameters

NameTypeDescription
fieldNamestring | keyof DocumentType & stringThe name of the field to query.
valuePrimitiveFieldTypeThe value to compare against.

Returns

QueryBuilder<DocumentType>

The query builder.

Inherited from

BaseQueryBuilder.gte


in

in(fieldName, value): QueryBuilder<DocumentType>

A shortcut for where(fieldName, 'in', value)

Parameters

NameTypeDescription
fieldNamestring | keyof DocumentType & stringThe name of the field to query.
valuePrimitiveFieldType[]An array of values to compare against.

Returns

QueryBuilder<DocumentType>

The query builder.

Inherited from

BaseQueryBuilder.in


like

like(fieldName, pattern, caseSensitive?): QueryBuilder<DocumentType>

A shortcut for where(fieldName, 'like', pattern).

Parameters

NameTypeDescription
fieldNamestring | keyof DocumentType & stringThe name of the field to query.
patternstringThe pattern to compare against. '%' matches 0 or more characters. '' matches exactly one character. '\' can be used to escape '%', ''. or another '\'. Note that any '\' that is not followed by '%', '_', or '\' is invalid.
caseSensitive?booleanWhether to use case-sensitive comparison. Defaults to true.

Returns

QueryBuilder<DocumentType>

The query builder.

Inherited from

BaseQueryBuilder.like


limit

limit(limit): QueryBuilder<DocumentType>

Sets a limit to the number of results returned by the query. The maximum limit is 20,000 and the default is 1,000 if none is provided.

Parameters

NameTypeDescription
limitnumberThe limit to set.

Returns

QueryBuilder<DocumentType>

The query builder.

Implementation of

SnapshotEmitter.limit

Overrides

BaseQueryBuilder.limit


limitBy

limitBy(limit, ...fields): QueryBuilder<DocumentType>

Parameters

NameType
limitnumber
...fieldsstring[]

Returns

QueryBuilder<DocumentType>


lt

lt(fieldName, value): QueryBuilder<DocumentType>

A shortcut for where(fieldName, '<', value)

Parameters

NameTypeDescription
fieldNamestring | keyof DocumentType & stringThe name of the field to query.
valuePrimitiveFieldTypeThe value to compare against.

Returns

QueryBuilder<DocumentType>

The query builder.

Inherited from

BaseQueryBuilder.lt


lte

lte(fieldName, value): QueryBuilder<DocumentType>

A shortcut for where(fieldName, '<=', value)

Parameters

NameTypeDescription
fieldNamestring | keyof DocumentType & stringThe name of the field to query.
valuePrimitiveFieldTypeThe value to compare against.

Returns

QueryBuilder<DocumentType>

The query builder.

Inherited from

BaseQueryBuilder.lte


neq

neq(fieldName, value): QueryBuilder<DocumentType>

A shortcut for where(fieldName, '!=', value)

Parameters

NameTypeDescription
fieldNamestring | keyof DocumentType & stringThe name of the field to query.
valuePrimitiveFieldTypeThe value to compare against.

Returns

QueryBuilder<DocumentType>

The query builder.

Inherited from

BaseQueryBuilder.neq


nin

nin(fieldName, value): QueryBuilder<DocumentType>

A shortcut for where(fieldName, 'not in', value)

Parameters

NameTypeDescription
fieldNamestring | keyof DocumentType & stringThe name of the field to query.
valuePrimitiveFieldType[]An array of values to compare against.

Returns

QueryBuilder<DocumentType>

The query builder.

Inherited from

BaseQueryBuilder.nin


notLike

notLike(fieldName, pattern, caseSensitive?): QueryBuilder<DocumentType>

A shortcut for where(fieldName, 'not like', pattern).

Parameters

NameTypeDescription
fieldNamestring | keyof DocumentType & stringThe name of the field to query.
patternstringThe pattern to compare against. '%' matches 0 or more characters. '' matches exactly one character. '\' can be used to escape '%', ''. or another '\'. Note that any '\' that is not followed by '%', '_', or '\' is invalid.
caseSensitive?booleanWhether to use case-sensitive comparison. Defaults to true.

Returns

QueryBuilder<DocumentType>

The query builder.

Inherited from

BaseQueryBuilder.notLike


paginate

paginate(options?): Pagination<DocumentReference<DocumentType>>

Returns a pagination wrapper for this query.

Parameters

NameTypeDescription
options?Partial<PaginationOptions>The pagination options. Defaults to { subscribe: true, pageSize: 100 }.

Returns

Pagination<DocumentReference<DocumentType>>

Implementation of

SnapshotEmitter.paginate


peek

peek(): DocumentReference<DocumentType>[]

Returns the results of the query based on the data that is currently available on the client. This method is useful for synchronously accessing data that has already been fetched by another query. The method will return an empty array if data has not yet been populated.

Returns

DocumentReference<DocumentType>[]

An array of query results.

Implementation of

SnapshotEmitter.peek


serialize

serialize(): SerializedSimpleQuery

Returns

SerializedSimpleQuery

Implementation of

SnapshotEmitter.serialize


setForceFetchFromServer

setForceFetchFromServer(): QueryBuilder<DocumentType>

Forces the query to return data from the server even if there is a query that already returned the requested result.

Returns

QueryBuilder<DocumentType>


snapshot

snapshot(): Promise<DocumentReference<DocumentType>[]>

Returns a promise that resolves to the query results.

Returns

Promise<DocumentReference<DocumentType>[]>

A promise that resolves to the query results.

Implementation of

SnapshotEmitter.snapshot


snapshots

snapshots(subscribe?): Observable<DocumentReference<DocumentType>[]>

Returns an observable that emits the query results and updates whenever the query results change unless subscribe=false is provided.

Important: Make sure to unsubscribe from the observable when you are done with it.

Parameters

NameTypeDefault valueDescription
subscribebooleantrueWhether to subscribe to changes to the query results. Defaults to true.

Returns

Observable<DocumentReference<DocumentType>[]>

An observable for the query results.

Implementation of

SnapshotEmitter.snapshots


sortBy

sortBy(fieldName, asc?): QueryBuilder<DocumentType>

Adds a sort order to the query. You can add multiple sort orders to the query. The order in which you add them determines the order in which they are applied.

Parameters

NameTypeDefault valueDescription
fieldNamestring | keyof DocumentType & stringundefinedThe name of the field to sort by.
ascbooleantrueWhether to sort in ascending order. Defaults to true.

Returns

QueryBuilder<DocumentType>

The query builder.

Overrides

BaseQueryBuilder.sortBy


throwIfInvalidLikePattern

throwIfInvalidLikePattern(pattern): void

Parameters

NameType
patternstring

Returns

void

Inherited from

BaseQueryBuilder.throwIfInvalidLikePattern


where

where(fieldName, operator, value): QueryBuilder<DocumentType>

Adds a condition to the query.

Parameters

NameTypeDescription
fieldNamestring | keyof DocumentType & stringThe name of the field to query.
operatorOperator | "in" | "not in"The operator to use.
valuePrimitiveFieldType | PrimitiveFieldType[]The value to compare against.

Returns

QueryBuilder<DocumentType>

The query builder.

Overrides

BaseQueryBuilder.where