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.

Index

Constructors

Protected constructor

Properties

firestore

firestore: Firestore

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

Methods

endAt

  • endAt(snapshot: DocumentSnapshot): Query
  • 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 orderBy of this query.

    Parameters

    Returns Query

    The created Query.

  • endAt(...fieldValues: any[]): Query
  • 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.

    Parameters

    • Rest ...fieldValues: any[]

      The field values to end this query at, in order of the query's order by.

    Returns Query

    The created Query.

endBefore

  • endBefore(snapshot: DocumentSnapshot): Query
  • 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 orderBy of this query.

    Parameters

    Returns Query

    The created Query.

  • endBefore(...fieldValues: any[]): Query
  • 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.

    Parameters

    • Rest ...fieldValues: any[]

      The field values to end this query before, in order of the query's order by.

    Returns Query

    The created Query.

get

  • get(options?: GetOptions): Promise<QuerySnapshot>
  • Executes the query and returns the results as a QuerySnapshot.

    Note: By default, get() 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 GetOptions parameter.

    Parameters

    • Optional options: GetOptions

      An object to configure the get behavior.

    Returns Promise<QuerySnapshot>

    A Promise that will be resolved with the results of the Query.

isEqual

  • isEqual(other: Query): boolean
  • Returns true if this Query is equal to the provided one.

    Parameters

    • other: Query

      The Query to compare against.

    Returns boolean

    true if this Query is equal to the provided one.

limit

  • limit(limit: number): Query
  • Creates and returns a new Query where the results are limited to the specified number of documents.

    Parameters

    • limit: number

      The maximum number of items to return.

    Returns Query

    The created Query.

onSnapshot

  • onSnapshot(observer: object): function
  • Attaches a listener for QuerySnapshot events. You may either pass individual onNext and onError callbacks or pass a single observer object with next and error callbacks. The listener can be cancelled by calling the function that is returned when onSnapshot is called.

    NOTE: Although an onCompletion callback can be provided, it will never be called because the snapshot stream is never-ending.

    Parameters

    • observer: object

      A single object containing next and error callbacks.

      • Optional complete?: function
          • (): void
          • Returns void

      • Optional error?: function
          • (error: Error): void
          • Parameters

            • error: Error

            Returns void

      • Optional next?: function

    Returns function

    An unsubscribe function that can be called to cancel the snapshot listener.

      • (): void
      • Returns void

  • onSnapshot(options: SnapshotListenOptions, observer: object): function
  • Attaches a listener for QuerySnapshot events. You may either pass individual onNext and onError callbacks or pass a single observer object with next and error callbacks. The listener can be cancelled by calling the function that is returned when onSnapshot is called.

    NOTE: Although an onCompletion callback can be provided, it will never be called because the snapshot stream is never-ending.

    Parameters

    • options: SnapshotListenOptions

      Options controlling the listen behavior.

    • observer: object

      A single object containing next and error callbacks.

      • Optional complete?: function
          • (): void
          • Returns void

      • Optional error?: function
          • (error: Error): void
          • Parameters

            • error: Error

            Returns void

      • Optional next?: function

    Returns function

    An unsubscribe function that can be called to cancel the snapshot listener.

      • (): void
      • Returns void

  • onSnapshot(onNext: function, onError?: function, onCompletion?: function): function
  • Attaches a listener for QuerySnapshot events. You may either pass individual onNext and onError callbacks or pass a single observer object with next and error callbacks. The listener can be cancelled by calling the function that is returned when onSnapshot is called.

    NOTE: Although an onCompletion callback can be provided, it will never be called because the snapshot stream is never-ending.

    Parameters

    • onNext: function

      A callback to be called every time a new QuerySnapshot is available.

    • Optional onError: function

      A callback to be called if the listen fails or is cancelled. No further callbacks will occur.

        • (error: Error): void
        • Parameters

          • error: Error

          Returns void

    • Optional onCompletion: function
        • (): void
        • Returns void

    Returns function

    An unsubscribe function that can be called to cancel the snapshot listener.

      • (): void
      • Returns void

  • onSnapshot(options: SnapshotListenOptions, onNext: function, onError?: function, onCompletion?: function): function
  • Attaches a listener for QuerySnapshot events. You may either pass individual onNext and onError callbacks or pass a single observer object with next and error callbacks. The listener can be cancelled by calling the function that is returned when onSnapshot is called.

    NOTE: Although an onCompletion callback can be provided, it will never be called because the snapshot stream is never-ending.

    Parameters

    • options: SnapshotListenOptions

      Options controlling the listen behavior.

    • onNext: function

      A callback to be called every time a new QuerySnapshot is available.

    • Optional onError: function

      A callback to be called if the listen fails or is cancelled. No further callbacks will occur.

        • (error: Error): void
        • Parameters

          • error: Error

          Returns void

    • Optional onCompletion: function
        • (): void
        • Returns void

    Returns function

    An unsubscribe function that can be called to cancel the snapshot listener.

      • (): void
      • Returns void

orderBy

  • orderBy(fieldPath: string | FieldPath, directionStr?: OrderByDirection): Query
  • Creates and returns a new Query that's additionally sorted by the specified field, optionally in descending order instead of ascending.

    Parameters

    • fieldPath: string | FieldPath

      The field to sort by.

    • Optional directionStr: OrderByDirection

      Optional direction to sort by (asc or desc). If not specified, order will be ascending.

    Returns Query

    The created Query.

startAfter

  • startAfter(snapshot: DocumentSnapshot): Query
  • 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 orderBy of this query.

    Parameters

    Returns Query

    The created Query.

  • startAfter(...fieldValues: any[]): Query
  • 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.

    Parameters

    • Rest ...fieldValues: any[]

      The field values to start this query after, in order of the query's order by.

    Returns Query

    The created Query.

startAt

  • startAt(snapshot: DocumentSnapshot): Query
  • 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 the orderBy of this query.

    Parameters

    Returns Query

    The created Query.

  • startAt(...fieldValues: any[]): Query
  • 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.

    Parameters

    • Rest ...fieldValues: any[]

      The field values to start this query at, in order of the query's order by.

    Returns Query

    The created Query.

where

  • where(fieldPath: string | FieldPath, opStr: WhereFilterOp, value: any): Query
  • Creates and returns a new Query with the additional filter that documents must contain the specified field and the value should satisfy the relation constraint provided.

    Parameters

    • fieldPath: string | FieldPath

      The path to compare

    • opStr: WhereFilterOp

      The operation string (e.g "<", "<=", "==", ">", ">=").

    • value: any

      The value for comparison

    Returns Query

    The created Query.

Enviar comentarios sobre...

Si necesitas ayuda, visita nuestra página de asistencia.