Firebase. Firestore. Query
A query which you can read or listen to.
Summary
You can also construct refinedQuery objects by adding filters, ordering, and other constraints.
CollectionReference derives from this class as a "return-all" query against the collection it refers to.
Inheritance
Direct Known Subclasses:Firebase.Firestore.CollectionReferenceProperties | |
|---|---|
Count | Returns a query that counts the documents in the result set of this query. |
Firestore | The CloudFirestore instance associated with this query. |
Public functions | |
|---|---|
EndAt(DocumentSnapshot snapshot) | Creates and returns a new Query that ends at the provided document (inclusive). |
EndAt(params object[] fieldValues) | Creates and returns a new Query that ends at the provided fields relative to the order of the query. |
EndBefore(DocumentSnapshot snapshot) | Creates and returns a new Query that ends before the provided document (exclusive). |
EndBefore(params object[] fieldValues) | Creates and returns a new Query that ends before the provided fields relative to the order of the query. |
Equals(object obj) | override bool |
Equals(Query other) | bool |
GetHashCode() | override int |
GetSnapshotAsync(Source source) | Task<QuerySnapshot >Asynchronously executes the query and returns all matching documents as a QuerySnapshot. |
Limit(int limit) | Creates and returns a new Query that only returns the last matching documents up to the specified number. |
LimitToLast(int limit) | Creates and returns a new Query that only returns the last matching documents up to the specified number. |
Listen(Action<QuerySnapshot > callback) | Starts listening to changes to the query results described by this Query. |
Listen(MetadataChanges metadataChanges, Action<QuerySnapshot > callback) | Starts listening to changes to the query results described by this Query. |
OrderBy(string fieldPath) | Creates and returns a new Query that's additionally sorted by the specified field. |
OrderBy(FieldPath fieldPath) | Creates and returns a new Query that's additionally sorted by the specified field. |
OrderByDescending(string fieldPath) | Creates and returns a new Query that's additionally sorted by the specified field in descending order. |
OrderByDescending(FieldPath fieldPath) | Creates and returns a new Query that's additionally sorted by the specified field in descending order. |
StartAfter(DocumentSnapshot snapshot) | Creates and returns a new Query that starts after the provided document (exclusive). |
StartAfter(params object[] fieldValues) | Creates and returns a new Query that starts after the provided fields relative to the order of the query. |
StartAt(DocumentSnapshot snapshot) | Creates and returns a new Query that starts at the provided document (inclusive). |
StartAt(params object[] fieldValues) | Creates and returns a new Query that starts at the provided fields relative to the order of the query. |
Where(Filter filter) | Creates and returns a newQuery with the additional filter. |
WhereArrayContains(FieldPath fieldPath, object value) | Creates and returns a new Query with the additional filter that documents must contain the specified field, the value must be an array, and that the array must contain the provided value. |
WhereArrayContains(string fieldPath, object value) | Creates and returns a new Query with the additional filter that documents must contain the specified field, the value must be an array, and that the array must contain the provided value. |
WhereArrayContainsAny(FieldPath fieldPath, IEnumerable< object > values) | Creates and returns a new Query with the additional filter that documents must contain the specified field, the value must be an array, and that the array must contain at least one value from the provided list. |
WhereArrayContainsAny(string fieldPath, IEnumerable< object > values) | Creates and returns a new Query with the additional filter that documents must contain the specified field, the value must be an array, and that the array must contain at least one value from the provided list. |
WhereEqualTo(string fieldPath, object value) | Creates and returns a new Query with the additional filter that documents must contain the specified field and the value should be equal to the specified value. |
WhereEqualTo(FieldPath fieldPath, object value) | Creates and returns a new Query with the additional filter that documents must contain the specified field and the value should be equal to the specified value. |
WhereGreaterThan(string fieldPath, object value) | Creates and returns a new Query with the additional filter that documents must contain the specified field and the value should be greater than the specified value. |
WhereGreaterThan(FieldPath fieldPath, object value) | Creates and returns a new Query with the additional filter that documents must contain the specified field and the value should be greater than the specified value. |
WhereGreaterThanOrEqualTo(string fieldPath, object value) | Creates and returns a new Query with the additional filter that documents must contain the specified field and the value should be greater than or equal to the specified value. |
WhereGreaterThanOrEqualTo(FieldPath fieldPath, object value) | Creates and returns a new Query with the additional filter that documents must contain the specified field and the value should be greater than or equal to the specified value. |
WhereIn(FieldPath fieldPath, IEnumerable< object > values) | Creates and returns a new Query with the additional filter that documents must contain the specified field and the value must equal one of the values from the provided list. |
WhereIn(string fieldPath, IEnumerable< object > values) | Creates and returns a new Query with the additional filter that documents must contain the specified field and the value must equal one of the values from the provided list. |
WhereLessThan(string fieldPath, object value) | Creates and returns a new Query with the additional filter that documents must contain the specified field and the value should be less than the specified value. |
WhereLessThan(FieldPath fieldPath, object value) | Creates and returns a new Query with the additional filter that documents must contain the specified field and the value should be less than the specified value. |
WhereLessThanOrEqualTo(string fieldPath, object value) | Creates and returns a new Query with the additional filter that documents must contain the specified field and the value should be less than or equal to the specified value. |
WhereLessThanOrEqualTo(FieldPath fieldPath, object value) | Creates and returns a new Query with the additional filter that documents must contain the specified field and the value should be less than or equal to the specified value. |
WhereNotEqualTo(string fieldPath, object value) | Creates and returns a new Query with the additional filter that documents must contain the specified field and the value should not equal the specified value. |
WhereNotEqualTo(FieldPath fieldPath, object value) | Creates and returns a new Query with the additional filter that documents must contain the specified field and the value should not equal the specified value. |
WhereNotIn(FieldPath fieldPath, IEnumerable< object > values) | Creates and returns a new Query with the additional filter that documents must contain the specified field and the value must not equal any value from the provided list. |
WhereNotIn(string fieldPath, IEnumerable< object > values) | Creates and returns a new Query with the additional filter that documents must contain the specified field and the value must not equal any value from the provided list. |
Properties
Count
AggregateQueryCount
Returns a query that counts the documents in the result set of this query.
The returned query, when executed, counts the documents in the result set of this query without actually downloading the documents.
Using the returned query to count the documents is efficient because only the final count, not the documents' data, is downloaded. The returned query can count the documents in cases where the result set is prohibitively large to download entirely (thousands of documents).
| Details | |
|---|---|
| Returns | An aggregate query that counts the documents in the result set of this query. |
Public functions
EndAt
QueryEndAt(DocumentSnapshotsnapshot)
Creates and returns a newQuery that ends at the provided document (inclusive).
The end position is relative to the order of the query. The document must contain all of the fields provided in the order-by clauses of the query.
This call replaces any previously specified end position in the query.
| Details | |||
|---|---|---|---|
| Parameters |
| ||
| Returns | A new query based on the current one, but with the specified end position. |
EndAt
QueryEndAt(paramsobject[]fieldValues)
Creates and returns a newQuery that ends at the provided fields relative to the order of the query.
The order of the field values must match the order of the order-by clauses of the query.
This call replaces any previously specified end position in the query.
| Details | |||
|---|---|---|---|
| Parameters |
| ||
| Returns | A new query based on the current one, but with the specified end position. |
EndBefore
QueryEndBefore(DocumentSnapshotsnapshot)
Creates and returns a newQuery that ends before the provided document (exclusive).
The end position is relative to the order of the query. The document must contain all of the fields provided in the order-by clauses of the query.
This call replaces any previously specified end position in the query.
| Details | |||
|---|---|---|---|
| Parameters |
| ||
| Returns | A new query based on the current one, but with the specified end position. |
EndBefore
QueryEndBefore(paramsobject[]fieldValues)
Creates and returns a newQuery that ends before the provided fields relative to the order of the query.
The order of the field values must match the order of the order-by clauses of the query.
This call replaces any previously specified end position in the query.
| Details | |||
|---|---|---|---|
| Parameters |
| ||
| Returns | A new query based on the current one, but with the specified end position. |
Equals
overrideboolEquals(objectobj)
Equals
boolEquals(Queryother)
GetHashCode
overrideintGetHashCode()
GetSnapshotAsync
Task<QuerySnapshot>GetSnapshotAsync(Sourcesource)
Asynchronously executes the query and returns all matching documents as aQuerySnapshot.
By default,GetSnapshotAsync attempts to provide up-to-date data when possible by waiting for data from the server, but it may return cached data or fail if you are offline and the server cannot be reached. This behavior can be altered via thesource parameter.
| Details | |||
|---|---|---|---|
| Parameters |
| ||
| Returns | A snapshot of documents matching the query. |
Limit
QueryLimit(intlimit)
Creates and returns a newQuery that only returns the last matching documents up to the specified number.
This call replaces any previously-specified limit in the query.
| Details | |||
|---|---|---|---|
| Parameters |
| ||
| Returns | A new query based on the current one, but with the specified limit applied. |
LimitToLast
QueryLimitToLast(intlimit)
Creates and returns a newQuery that only returns the last matching documents up to the specified number.
You must specify at least oneOrderBy clause forLimitToLast queries, otherwise an exception will be thrown during execution.
This call replaces any previously-specified limit in the query.
| Details | |||
|---|---|---|---|
| Parameters |
| ||
| Returns | A new query based on the current one, but with the specified limit applied. |
Listen
ListenerRegistrationListen(Action<QuerySnapshot>callback)
Starts listening to changes to the query results described by thisQuery.
| Details | |||
|---|---|---|---|
| Parameters |
| ||
| Returns | AListenerRegistration which may be used to stop listening gracefully. |
Listen
ListenerRegistrationListen(MetadataChangesmetadataChanges,Action<QuerySnapshot>callback)
Starts listening to changes to the query results described by thisQuery.
| Details | |||||
|---|---|---|---|---|---|
| Parameters |
| ||||
| Returns | AListenerRegistration which may be used to stop listening gracefully. |
OrderBy
QueryOrderBy(stringfieldPath)
Creates and returns a newQuery that's additionally sorted by the specified field.
Unlike OrderBy in LINQ, this call makes each additional ordering subordinate to the preceding ones. This means thatquery.OrderBy("foo").OrderBy("bar") in CloudFirestore is similar toquery.OrderBy(x => x.Foo).ThenBy(x => x.Bar) in LINQ.
This method cannot be called after a start/end cursor has been specified withStartAt(DocumentSnapshot),StartAfter(DocumentSnapshot),EndAt(DocumentSnapshot) orEndBefore(DocumentSnapshot) or other overloads.
| Details | |||
|---|---|---|---|
| Parameters |
| ||
| Returns | A new query based on the current one, but with the additional specified ordering applied. |
OrderBy
QueryOrderBy(FieldPathfieldPath)
Creates and returns a newQuery that's additionally sorted by the specified field.
Unlike OrderBy in LINQ, this call makes each additional ordering subordinate to the preceding ones. This means thatquery.OrderBy("foo").OrderBy("bar") in CloudFirestore is similar toquery.OrderBy(x => x.Foo).ThenBy(x => x.Bar) in LINQ.
This method cannot be called after a start/end cursor has been specified withStartAt(DocumentSnapshot),StartAfter(DocumentSnapshot),EndAt(DocumentSnapshot) orEndBefore(DocumentSnapshot) or other overloads.
| Details | |||
|---|---|---|---|
| Parameters |
| ||
| Returns | A new query based on the current one, but with the additional specified ordering applied. |
OrderByDescending
QueryOrderByDescending(stringfieldPath)
Creates and returns a newQuery that's additionally sorted by the specified field in descending order.
Unlike OrderByDescending in LINQ, this call makes each additional ordering subordinate to the preceding ones. This means thatquery.OrderByDescending("foo").OrderByDescending("bar") in CloudFirestore is similar toquery.OrderByDescending(x => x.Foo).ThenByDescending(x => x.Bar) in LINQ.
This method cannot be called after a start/end cursor has been specified withStartAt(DocumentSnapshot),StartAfter(DocumentSnapshot),EndAt(DocumentSnapshot) orEndBefore(DocumentSnapshot) or other overloads.
| Details | |||
|---|---|---|---|
| Parameters |
| ||
| Returns | A new query based on the current one, but with the additional specified ordering applied. |
OrderByDescending
QueryOrderByDescending(FieldPathfieldPath)
Creates and returns a newQuery that's additionally sorted by the specified field in descending order.
Unlike OrderByDescending in LINQ, this call makes each additional ordering subordinate to the preceding ones. This means thatquery.OrderByDescending("foo").OrderByDescending("bar") in CloudFirestore is similar toquery.OrderByDescending(x => x.Foo).ThenByDescending(x => x.Bar) in LINQ.
This method cannot be called after a start/end cursor has been specified withStartAt(DocumentSnapshot),StartAfter(DocumentSnapshot),EndAt(DocumentSnapshot) orEndBefore(DocumentSnapshot) or other overloads.
| Details | |||
|---|---|---|---|
| Parameters |
| ||
| Returns | A new query based on the current one, but with the additional specified ordering applied. |
StartAfter
QueryStartAfter(DocumentSnapshotsnapshot)
Creates and returns a newQuery that starts after the provided document (exclusive).
The starting position is relative to the order of the query. The document must contain all of the fields provided in the order-by clauses of the query.
This call replaces any previously specified start position in the query.
| Details | |||
|---|---|---|---|
| Parameters |
| ||
| Returns | A new query based on the current one, but with the specified start position. |
StartAfter
QueryStartAfter(paramsobject[]fieldValues)
Creates and returns a newQuery that starts after the provided fields relative to the order of the query.
The order of the field values must match the order of the order-by clauses of the query.
This call replaces any previously specified start position in the query.
| Details | |||
|---|---|---|---|
| Parameters |
| ||
| Returns | A new query based on the current one, but with the specified start position. |
StartAt
QueryStartAt(DocumentSnapshotsnapshot)
Creates and returns a newQuery that starts at the provided document (inclusive).
The starting position is relative to the order of the query. The document must contain all of the fields provided in order-by clauses of the query.
This call replaces any previously specified start position in the query.
| Details | |||
|---|---|---|---|
| Parameters |
| ||
| Returns | A new query based on the current one, but with the specified start position. |
StartAt
QueryStartAt(paramsobject[]fieldValues)
Creates and returns a newQuery that starts at the provided fields relative to the order of the query.
The order of the field values must match the order of the order-by clauses of the query.
This call replaces any previously specified start position in the query.
| Details | |||
|---|---|---|---|
| Parameters |
| ||
| Returns | A new query based on the current one, but with the specified start position. |
WhereArrayContains
QueryWhereArrayContains(FieldPathfieldPath,objectvalue)
Creates and returns a newQuery with the additional filter that documents must contain the specified field, the value must be an array, and that the array must contain the provided value.
AQuery can have only oneWhereArrayContains() filter and it cannot be combined withWhereArrayContainsAny().
| Details | |||||
|---|---|---|---|---|---|
| Parameters |
| ||||
| Returns | A new query based on the current one, but with the additional filter applied. |
WhereArrayContains
QueryWhereArrayContains(stringfieldPath,objectvalue)
Creates and returns a newQuery with the additional filter that documents must contain the specified field, the value must be an array, and that the array must contain the provided value.
AQuery can have only oneWhereArrayContains() filter and it cannot be combined withWhereArrayContainsAny().
| Details | |||||
|---|---|---|---|---|---|
| Parameters |
| ||||
| Returns | A new query based on the current one, but with the additional filter applied. |
WhereArrayContainsAny
QueryWhereArrayContainsAny(FieldPathfieldPath,IEnumerable<object>values)
Creates and returns a newQuery with the additional filter that documents must contain the specified field, the value must be an array, and that the array must contain at least one value from the provided list.
AQuery can have only oneWhereArrayContainsAny() filter and it cannot be combined withWhereArrayContains() orWhereIn().
| Details | |||||
|---|---|---|---|---|---|
| Parameters |
| ||||
| Returns | A new query based on the current one, but with the additional filter applied. |
WhereArrayContainsAny
QueryWhereArrayContainsAny(stringfieldPath,IEnumerable<object>values)
Creates and returns a newQuery with the additional filter that documents must contain the specified field, the value must be an array, and that the array must contain at least one value from the provided list.
AQuery can have only oneWhereArrayContainsAny() filter and it cannot be combined withWhereArrayContains() orWhereIn().
| Details | |||||
|---|---|---|---|---|---|
| Parameters |
| ||||
| Returns | A new query based on the current one, but with the additional filter applied. |
WhereEqualTo
QueryWhereEqualTo(stringfieldPath,objectvalue)
Creates and returns a newQuery with the additional filter that documents must contain the specified field and the value should be equal to the specified value.
| Details | |||||
|---|---|---|---|---|---|
| Parameters |
| ||||
| Returns | A new query based on the current one, but with the additional filter applied. |
WhereEqualTo
QueryWhereEqualTo(FieldPathfieldPath,objectvalue)
Creates and returns a newQuery with the additional filter that documents must contain the specified field and the value should be equal to the specified value.
| Details | |||||
|---|---|---|---|---|---|
| Parameters |
| ||||
| Returns | A new query based on the current one, but with the additional filter applied. |
WhereGreaterThan
QueryWhereGreaterThan(stringfieldPath,objectvalue)
Creates and returns a newQuery with the additional filter that documents must contain the specified field and the value should be greater than the specified value.
| Details | |||||
|---|---|---|---|---|---|
| Parameters |
| ||||
| Returns | A new query based on the current one, but with the additional filter applied. |
WhereGreaterThan
QueryWhereGreaterThan(FieldPathfieldPath,objectvalue)
Creates and returns a newQuery with the additional filter that documents must contain the specified field and the value should be greater than the specified value.
| Details | |||||
|---|---|---|---|---|---|
| Parameters |
| ||||
| Returns | A new query based on the current one, but with the additional filter applied. |
WhereGreaterThanOrEqualTo
QueryWhereGreaterThanOrEqualTo(stringfieldPath,objectvalue)
Creates and returns a newQuery with the additional filter that documents must contain the specified field and the value should be greater than or equal to the specified value.
| Details | |||||
|---|---|---|---|---|---|
| Parameters |
| ||||
| Returns | A new query based on the current one, but with the additional filter applied. |
WhereGreaterThanOrEqualTo
QueryWhereGreaterThanOrEqualTo(FieldPathfieldPath,objectvalue)
Creates and returns a newQuery with the additional filter that documents must contain the specified field and the value should be greater than or equal to the specified value.
| Details | |||||
|---|---|---|---|---|---|
| Parameters |
| ||||
| Returns | A new query based on the current one, but with the additional filter applied. |
WhereIn
QueryWhereIn(FieldPathfieldPath,IEnumerable<object>values)
Creates and returns a newQuery with the additional filter that documents must contain the specified field and the value must equal one of the values from the provided list.
AQuery can have only oneWhereIn() filter and it cannot be combined withWhereArrayContainsAny().
| Details | |||||
|---|---|---|---|---|---|
| Parameters |
| ||||
| Returns | A new query based on the current one, but with the additional filter applied. |
WhereIn
QueryWhereIn(stringfieldPath,IEnumerable<object>values)
Creates and returns a newQuery with the additional filter that documents must contain the specified field and the value must equal one of the values from the provided list.
AQuery can have only oneWhereIn() filter and it cannot be combined withWhereArrayContainsAny().
| Details | |||||
|---|---|---|---|---|---|
| Parameters |
| ||||
| Returns | A new query based on the current one, but with the additional filter applied. |
WhereLessThan
QueryWhereLessThan(stringfieldPath,objectvalue)
Creates and returns a newQuery with the additional filter that documents must contain the specified field and the value should be less than the specified value.
| Details | |||||
|---|---|---|---|---|---|
| Parameters |
| ||||
| Returns | A new query based on the current one, but with the additional filter applied. |
WhereLessThan
QueryWhereLessThan(FieldPathfieldPath,objectvalue)
Creates and returns a newQuery with the additional filter that documents must contain the specified field and the value should be less than the specified value.
| Details | |||||
|---|---|---|---|---|---|
| Parameters |
| ||||
| Returns | A new query based on the current one, but with the additional filter applied. |
WhereLessThanOrEqualTo
QueryWhereLessThanOrEqualTo(stringfieldPath,objectvalue)
Creates and returns a newQuery with the additional filter that documents must contain the specified field and the value should be less than or equal to the specified value.
| Details | |||||
|---|---|---|---|---|---|
| Parameters |
| ||||
| Returns | A new query based on the current one, but with the additional filter applied. |
WhereLessThanOrEqualTo
QueryWhereLessThanOrEqualTo(FieldPathfieldPath,objectvalue)
Creates and returns a newQuery with the additional filter that documents must contain the specified field and the value should be less than or equal to the specified value.
| Details | |||||
|---|---|---|---|---|---|
| Parameters |
| ||||
| Returns | A new query based on the current one, but with the additional filter applied. |
WhereNotEqualTo
QueryWhereNotEqualTo(stringfieldPath,objectvalue)
Creates and returns a newQuery with the additional filter that documents must contain the specified field and the value should not equal the specified value.
AQuery can have only oneWhereNotEqualTo() filter, and it cannot be combined withWhereNotIn().
| Details | |||||
|---|---|---|---|---|---|
| Parameters |
| ||||
| Returns | A new query based on the current one, but with the additional filter applied. |
WhereNotEqualTo
QueryWhereNotEqualTo(FieldPathfieldPath,objectvalue)
Creates and returns a newQuery with the additional filter that documents must contain the specified field and the value should not equal the specified value.
AQuery can have only oneWhereNotEqualTo() filter, and it cannot be combined withWhereNotIn().
| Details | |||||
|---|---|---|---|---|---|
| Parameters |
| ||||
| Returns | A new query based on the current one, but with the additional filter applied. |
WhereNotIn
QueryWhereNotIn(FieldPathfieldPath,IEnumerable<object>values)
Creates and returns a newQuery with the additional filter that documents must contain the specified field and the value must not equal any value from the provided list.
One special case is thatWhereNotIn cannot match null values. To query for documents where a field exists and is null, useWhereNotEqualTo, which can handle this special case.
AQuery can have only oneWhereNotIn() filter, and it cannot be combined withWhereArrayContains(),WhereArrayContainsAny(),WhereIn(), orWhereNotEqualTo().
| Details | |||||
|---|---|---|---|---|---|
| Parameters |
| ||||
| Returns | A new query based on the current one, but with the additional filter applied. |
WhereNotIn
QueryWhereNotIn(stringfieldPath,IEnumerable<object>values)
Creates and returns a newQuery with the additional filter that documents must contain the specified field and the value must not equal any value from the provided list.
One special case is thatWhereNotIn cannot match null values. To query for documents where a field exists and is null, useWhereNotEqualTo, which can handle this special case.
AQuery can have only oneWhereNotIn() filter, and it cannot be combined withWhereArrayContains(),WhereArrayContainsAny(),WhereIn(), orWhereNotEqualTo().
| Details | |||||
|---|---|---|---|---|---|
| Parameters |
| ||||
| Returns | A new query based on the current one, but with the additional filter applied. |
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-02-13 UTC.