Options
All
  • Public
  • Public/Protected
  • All
Menu

These objects are returned when using find-like functionality on Collection.

They allow chaining of further query-related functions to do things like add a limit to the number of documents you want returned or specify how you want the documents to be sorted and ordered.

You can either call exec() on the object to get an array of documents as an immediate return value, or you can establish either a live query or a subscription, which both work over time.

A live query, established by calling observe(), will notify you every time there's an update to a document that matches the query you provided in the preceding find-like call.

A subscription, established by calling subscribe(), will act as a signal to other peers that the device connects to that you would like to receive updates from them about documents that match the query you provided in the preceding find-like call.

Calling observe() will generate both a subscription and a live query at the same time.

If you'd like to only observe local changes then you can call observeLocal().

Update and remove functionality is also exposed through this object.

Hierarchy

  • PendingCursorOperation

Implements

Index

Properties

Readonly collection

collection: Collection

The collection the receiver is operating on.

Readonly query

query: string

The query the receiver is operating with.

Readonly queryArgs

queryArgs: QueryArguments

The named arguments for the query.

Methods

evict

  • evict(): Promise<any[]>
  • Evicts all documents that match the query generated by the preceding function chaining.

    Returns Promise<any[]>

    An array promise containing the IDs of the documents that were evicted.

exec

  • exec(): Promise<any[]>
  • Executes the query generated by the preceding function chaining and return the list of matching documents.

    Returns Promise<any[]>

    An array promise containing documents matching the query generated by the preceding function chaining.

limit

  • Limits the number of documents that get returned when querying a collection for matching documents.

    Parameters

    • limit: number

      The maximum number of documents that will be returned.

    Returns PendingCursorOperation

    A PendingCursorOperation that you can chain further function calls and then either get the matching documents immediately or get updates about them over time.

observe

  • Enables you to subscribe to changes that occur in a collection locally and remotely.

    The handler block will be called when local or remote changes are made to documents that match the query generated by the chain of operations that precedes the call to observe(). The returned LiveQuery object must be kept in scope for as long as you want the provided handler to be called when an update occurs.

    Parameters

    • handler: QueryObservationHandler

      A closure that will be called every time there is a transaction committed to the store that involves modifications to documents matching the query in the collection that this method was called on.

    Returns LiveQuery

    A LiveQuery object that must be kept in scope for as long as you want to keep receiving updates.

observeLocal

  • Enables you to subscribe to changes that occur in a collection locally.

    This won't subscribe to receive changes made remotely by others and so it will only fire updates when a local change is made. If you want to receive remotely performed updates as well then use observe() or call subscribe() with the relevant query. The returned LiveQuery object must be kept in scope for as long as you want the provided eventHandler to be called when an update occurs.

    Parameters

    • handler: QueryObservationHandler

      A closure that will be called every time there is a transaction committed to the store that involves modifications to documents matching the query in the collection this method was called on.

    Returns LiveQuery

    A LiveQuery object that must be kept in scope for as long as you want to keep receiving updates.

observeLocalWithNextSignal

  • Enables you to subscribe to changes that occur in a collection locally and to signal when you are ready for the live query to deliver the next event.

    The handler block will be called when local or remote changes are made to documents that match the query generated by the chain of operations that precedes the call to observe(). The returned LiveQuery object must be kept in scope for as long as you want the provided handler to be called when an update occurs.

    Parameters

    • handler: QueryObservationHandler

      A closure that will be called every time there is a transaction committed to the store that involves modifications to documents matching the query in the collection that this method was called on.

    Returns LiveQuery

    A LiveQuery object that must be kept in scope for as long as you want to keep receiving updates.

observeWithNextSignal

  • Enables you to subscribe to changes that occur in a collection locally and remotely, and to signal when you are ready for the live query to deliver the next event.

    The handler block will be called when local or remote changes are made to documents that match the query generated by the chain of operations that precedes the call to observe(). The returned LiveQuery object must be kept in scope for as long as you want the provided handler to be called when an update occurs.

    Parameters

    • handler: QueryObservationHandler

      A closure that will be called every time there is a transaction committed to the store that involves modifications to documents matching the query in the collection that this method was called on.

    Returns LiveQuery

    A LiveQuery object that must be kept in scope for as long as you want to keep receiving updates.

offset

  • Offsets the resulting set of matching documents.

    This is useful if you aren't interested in the first N matching documents for one reason or another. For example, you might already have queried the collection and obtained the first 20 matching documents and so you might want to run the same query as you did previously but ignore the first 20 matching documents, and that is when you would use offset.

    Parameters

    • offset: number

      The number of matching documents that you want the eventual resulting set of matching documents to be offset by (and thus not include).

    Returns PendingCursorOperation

    A PendingCursorOperation that you can chain further function calls and then either get the matching documents immediately or get updates about them over time.

remove

  • remove(): Promise<any[]>
  • Removes all documents that match the query generated by the preceding function chaining.

    Returns Promise<any[]>

    An array promise containing the IDs of the documents that were removed.

sort

  • Sorts the documents that match the query provided in the preceding find-like function call.

    Parameters

    • propertyPath: string
    • Optional direction: SortDirection

      Specify whether you want the sorting order to be Ascending or Descending.

    Returns PendingCursorOperation

    A PendingCursorOperation that you can chain further function calls and then either get the matching documents immediately or get updates about them over time.

subscribe

  • Enables you to subscribe to changes that occur in a collection remotely.

    Having a subscription acts as a signal to other peers that you are interested in receiving updates when local or remote changes are made to documents that match the query generated by the chain of operations that precedes the call to subscribe().

    The returned Subscription object must be kept in scope for as long as you want to keep receiving updates.

    Returns Subscription

    A Subscription object that must be kept in scope for as long as you want to keep receiving updates for documents that match the query specified in the preceding chain.

update

  • Updates documents that match the query generated by the preceding function chaining.

    Parameters

    • closure: (documents: any[]) => void

      A closure that gets called with all of the documents matching the query. The documents are instances of MutableDocument so you can call update-related functions on them.

        • (documents: any[]): void
        • Parameters

          • documents: any[]

          Returns void

    Returns Promise<UpdateResultsMap>

    An UpdateResultsMap promise mapping document IDs to lists of update results that describe the updates that were performed for each document.