Firebase.Firestore.Query

A query which you can read or listen to.

Summary

You can also construct refined Query 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.CollectionReference

Properties

Count
Returns a query that counts the documents in the result set of this query.
Firestore
The Cloud Firestore 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 new Query 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

AggregateQuery Count

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.

Firestore

FirebaseFirestore Firestore

The Cloud Firestore instance associated with this query.

Public functions

EndAt

Query EndAt(
  DocumentSnapshot snapshot
)

Creates and returns a new Query 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
snapshot
The snapshot of the document to end at.
Returns
A new query based on the current one, but with the specified end position.

EndAt

Query EndAt(
  params object[] fieldValues
)

Creates and returns a new Query 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
fieldValues
The field values. The fieldValues array must not be null or empty (though elements of the array may be), or have more values than query has orderings.
Returns
A new query based on the current one, but with the specified end position.

EndBefore

Query EndBefore(
  DocumentSnapshot snapshot
)

Creates and returns a new Query 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
snapshot
The snapshot of the document to end before.
Returns
A new query based on the current one, but with the specified end position.

EndBefore

Query EndBefore(
  params object[] fieldValues
)

Creates and returns a new Query 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
fieldValues
The field values. The fieldValues array must not be null or empty (though elements of the array may be), or have more values than query has orderings.
Returns
A new query based on the current one, but with the specified end position.

Equals

override bool Equals(
  object obj
)

Equals

bool Equals(
  Query other
)

GetHashCode

override int GetHashCode()

GetSnapshotAsync

Task< QuerySnapshot > GetSnapshotAsync(
  Source source
)

Asynchronously executes the query and returns all matching documents as a QuerySnapshot.

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 the source parameter.

Details
Parameters
source
indicates whether the results should be fetched from the cache only (Source.Cache), the server only (Source.Server), or to attempt the server and fall back to the cache (Source.Default).
Returns
A snapshot of documents matching the query.

Limit

Query Limit(
  int limit
)

Creates and returns a new Query that only returns the last matching documents up to the specified number.

This call replaces any previously-specified limit in the query.

Details
Parameters
limit
The maximum number of items to return. Must be greater than 0.
Returns
A new query based on the current one, but with the specified limit applied.

LimitToLast

Query LimitToLast(
  int limit
)

Creates and returns a new Query that only returns the last matching documents up to the specified number.

You must specify at least one OrderBy clause for LimitToLast queries, otherwise an exception will be thrown during execution.

This call replaces any previously-specified limit in the query.

Details
Parameters
limit
The maximum number of items to return. Must be greater than 0.
Returns
A new query based on the current one, but with the specified limit applied.

Listen

ListenerRegistration Listen(
  Action< QuerySnapshot > callback
)

Starts listening to changes to the query results described by this Query.

Details
Parameters
callback
The callback to invoke each time the query results change. Must not be null. The callback will be invoked on the main thread.
Returns
A ListenerRegistration which may be used to stop listening gracefully.

Listen

ListenerRegistration Listen(
  MetadataChanges metadataChanges,
  Action< QuerySnapshot > callback
)

Starts listening to changes to the query results described by this Query.

Details
Parameters
metadataChanges
Indicates whether metadata-only changes (i.e. only QuerySnapshot.Metadata changed) should trigger snapshot events.
callback
The callback to invoke each time the query results change. Must not be null. The callback will be invoked on the main thread.
Returns
A ListenerRegistration which may be used to stop listening gracefully.

OrderBy

Query OrderBy(
  string fieldPath
)

Creates and returns a new Query 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 that query.OrderBy("foo").OrderBy("bar") in Cloud Firestore is similar to query.OrderBy(x => x.Foo).ThenBy(x => x.Bar) in LINQ.

This method cannot be called after a start/end cursor has been specified with StartAt(DocumentSnapshot), StartAfter(DocumentSnapshot), EndAt(DocumentSnapshot) or EndBefore(DocumentSnapshot) or other overloads.

Details
Parameters
fieldPath
The dot-separated field path to order by. Must not be null or empty.
Returns
A new query based on the current one, but with the additional specified ordering applied.

OrderBy

Query OrderBy(
  FieldPath fieldPath
)

Creates and returns a new Query 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 that query.OrderBy("foo").OrderBy("bar") in Cloud Firestore is similar to query.OrderBy(x => x.Foo).ThenBy(x => x.Bar) in LINQ.

This method cannot be called after a start/end cursor has been specified with StartAt(DocumentSnapshot), StartAfter(DocumentSnapshot), EndAt(DocumentSnapshot) or EndBefore(DocumentSnapshot) or other overloads.

Details
Parameters
fieldPath
The field path to order by. Must not be null.
Returns
A new query based on the current one, but with the additional specified ordering applied.

OrderByDescending

Query OrderByDescending(
  string fieldPath
)

Creates and returns a new Query 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 that query.OrderByDescending("foo").OrderByDescending("bar") in Cloud Firestore is similar to query.OrderByDescending(x => x.Foo).ThenByDescending(x => x.Bar) in LINQ.

This method cannot be called after a start/end cursor has been specified with StartAt(DocumentSnapshot), StartAfter(DocumentSnapshot), EndAt(DocumentSnapshot) or EndBefore(DocumentSnapshot) or other overloads.

Details
Parameters
fieldPath
The dot-separated field path to order by. Must not be null or empty.
Returns
A new query based on the current one, but with the additional specified ordering applied.

OrderByDescending

Query OrderByDescending(
  FieldPath fieldPath
)

Creates and returns a new Query 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 that query.OrderByDescending("foo").OrderByDescending("bar") in Cloud Firestore is similar to query.OrderByDescending(x => x.Foo).ThenByDescending(x => x.Bar) in LINQ.

This method cannot be called after a start/end cursor has been specified with StartAt(DocumentSnapshot), StartAfter(DocumentSnapshot), EndAt(DocumentSnapshot) or EndBefore(DocumentSnapshot) or other overloads.

Details
Parameters
fieldPath
The field path to order by. Must not be null.
Returns
A new query based on the current one, but with the additional specified ordering applied.

StartAfter

Query StartAfter(
  DocumentSnapshot snapshot
)

Creates and returns a new Query 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
snapshot
The snapshot of the document to start after.
Returns
A new query based on the current one, but with the specified start position.

StartAfter

Query StartAfter(
  params object[] fieldValues
)

Creates and returns a new Query 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
fieldValues
The field values. The fieldValues array must not be null or empty (though elements of the array may be), or have more values than query has orderings.
Returns
A new query based on the current one, but with the specified start position.

StartAt

Query StartAt(
  DocumentSnapshot snapshot
)

Creates and returns a new Query 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
snapshot
The snapshot of the document to start at.
Returns
A new query based on the current one, but with the specified start position.

StartAt

Query StartAt(
  params object[] fieldValues
)

Creates and returns a new Query 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
fieldValues
The field values. The fieldValues array must not be null or empty (though elements of the array may be), or have more values than query has orderings.
Returns
A new query based on the current one, but with the specified start position.

Where

Query Where(
  Filter filter
)

Creates and returns a new Query with the additional filter.

Details
Parameters
filter
The new filter to apply to the existing query.
Returns
The created Query.

WhereArrayContains

Query 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.

A Query can have only one WhereArrayContains() filter and it cannot be combined with WhereArrayContainsAny().

Details
Parameters
fieldPath
The name of the fields containing an array to search
value
The value that must be contained in the array.
Returns
A new query based on the current one, but with the additional filter applied.

WhereArrayContains

Query 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.

A Query can have only one WhereArrayContains() filter and it cannot be combined with WhereArrayContainsAny().

Details
Parameters
fieldPath
The dot-separated field path to filter on. Must not be null or empty.
value
The value that must be contained in the array.
Returns
A new query based on the current one, but with the additional filter applied.

WhereArrayContainsAny

Query 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.

A Query can have only one WhereArrayContainsAny() filter and it cannot be combined with WhereArrayContains() or WhereIn().

Details
Parameters
fieldPath
The name of the fields containing an array to search.
values
The list that contains the values to match.
Returns
A new query based on the current one, but with the additional filter applied.

WhereArrayContainsAny

Query 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.

A Query can have only one WhereArrayContainsAny() filter and it cannot be combined with WhereArrayContains() or WhereIn().

Details
Parameters
fieldPath
The dot-separated field path to filter on. Must not be null or empty.
values
The list that contains the values to match.
Returns
A new query based on the current one, but with the additional filter applied.

WhereEqualTo

Query 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.

Details
Parameters
fieldPath
The dot-separated field path to filter on. Must not be null or empty.
value
The value to compare in the filter.
Returns
A new query based on the current one, but with the additional filter applied.

WhereEqualTo

Query 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.

Details
Parameters
fieldPath
The field path to filter on. Must not be null.
value
The value to compare in the filter.
Returns
A new query based on the current one, but with the additional filter applied.

WhereGreaterThan

Query 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.

Details
Parameters
fieldPath
The dot-separated field path to filter on. Must not be null or empty.
value
The value to compare in the filter.
Returns
A new query based on the current one, but with the additional filter applied.

WhereGreaterThan

Query 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.

Details
Parameters
fieldPath
The field path to filter on. Must not be null.
value
The value to compare in the filter.
Returns
A new query based on the current one, but with the additional filter applied.

WhereGreaterThanOrEqualTo

Query 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.

Details
Parameters
fieldPath
The dot-separated field path to filter on. Must not be null or empty.
value
The value to compare in the filter.
Returns
A new query based on the current one, but with the additional filter applied.

WhereGreaterThanOrEqualTo

Query 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.

Details
Parameters
fieldPath
The field path to filter on. Must not be null.
value
The value to compare in the filter.
Returns
A new query based on the current one, but with the additional filter applied.

WhereIn

Query 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.

A Query can have only one WhereIn() filter and it cannot be combined with WhereArrayContainsAny().

Details
Parameters
fieldPath
The name of the fields containing an array to search.
values
The list that contains the values to match.
Returns
A new query based on the current one, but with the additional filter applied.

WhereIn

Query 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.

A Query can have only one WhereIn() filter and it cannot be combined with WhereArrayContainsAny().

Details
Parameters
fieldPath
The dot-separated field path to filter on. Must not be null or empty.
values
The list that contains the values to match.
Returns
A new query based on the current one, but with the additional filter applied.

WhereLessThan

Query 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.

Details
Parameters
fieldPath
The dot-separated field path to filter on. Must not be null or empty.
value
The value to compare in the filter.
Returns
A new query based on the current one, but with the additional filter applied.

WhereLessThan

Query 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.

Details
Parameters
fieldPath
The field path to filter on. Must not be null.
value
The value to compare in the filter.
Returns
A new query based on the current one, but with the additional filter applied.

WhereLessThanOrEqualTo

Query 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.

Details
Parameters
fieldPath
The dot-separated field path to filter on. Must not be null or empty.
value
The value to compare in the filter.
Returns
A new query based on the current one, but with the additional filter applied.

WhereLessThanOrEqualTo

Query 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.

Details
Parameters
fieldPath
The field path to filter on. Must not be null.
value
The value to compare in the filter.
Returns
A new query based on the current one, but with the additional filter applied.

WhereNotEqualTo

Query 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.

A Query can have only one WhereNotEqualTo() filter, and it cannot be combined with WhereNotIn().

Details
Parameters
fieldPath
The dot-separated field path to filter on. Must not be null or empty.
value
The value to compare in the filter.
Returns
A new query based on the current one, but with the additional filter applied.

WhereNotEqualTo

Query 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.

A Query can have only one WhereNotEqualTo() filter, and it cannot be combined with WhereNotIn().

Details
Parameters
fieldPath
The field path to filter on. Must not be null.
value
The value to compare in the filter.
Returns
A new query based on the current one, but with the additional filter applied.

WhereNotIn

Query 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.

One special case is that WhereNotIn cannot match null values. To query for documents where a field exists and is null, use WhereNotEqualTo, which can handle this special case.

A Query can have only one WhereNotIn() filter, and it cannot be combined with WhereArrayContains(), WhereArrayContainsAny(), WhereIn(), or WhereNotEqualTo().

Details
Parameters
fieldPath
The name of the fields containing an array to search.
values
The list that contains the values to match.
Returns
A new query based on the current one, but with the additional filter applied.

WhereNotIn

Query 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.

One special case is that WhereNotIn cannot match null values. To query for documents where a field exists and is null, use WhereNotEqualTo, which can handle this special case.

A Query can have only one WhereNotIn() filter, and it cannot be combined with WhereArrayContains(), WhereArrayContainsAny(), WhereIn(), or WhereNotEqualTo().

Details
Parameters
fieldPath
The name of the fields containing an array to search.
values
The list that contains the values to match.
Returns
A new query based on the current one, but with the additional filter applied.