Options
All
  • Public
  • Public/Protected
  • All
Menu

These objects are returned when using findByID() functionality on collections.

You can either call exec() on the object to get 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 the document with the ID you provided in the preceding findByID() call.

A subscription, established by calling subscribe(), will act as a signal to other peers that you would like to receive updates from them about the document with the ID you provided in the preceding findByID() 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

  • PendingIDSpecificOperation

Implements

Index

Properties

Readonly collection

collection: Collection

The collection the receiver is operating on.

Readonly documentID

documentID: any

The ID of the document this operation operates on.

Methods

evict

  • evict(): Promise<boolean>
  • Evicts the document with the matching ID.

    Returns Promise<boolean>

    true promise if the document was found and evicted. false promise if the document wasn't found and therefore wasn't evicted.

exec

  • exec(): Promise<any>
  • Executes the find operation to return the document with the matching ID.

    Returns Promise<any>

    The Document promise with the ID provided in the findByID() call or undefined if the document was not found.

observe

  • Enables you to listen for changes that occur in relation to a document locally and remotely.

    The handler closure will be called when local or remote changes are made to the document referenced by the findByID() call 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: SingleObservationHandler

      A closure that will be called every time there is a transaction committed to the store that involves a modification to the document with the relevant ID in the collection that observe() 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 listen for changes that occur in relation to a document 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 also call subscribe() separately, using another findByID() call that references the same document ID.

    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: SingleObservationHandler

      A block that will be called every time there is a transaction committed to the store that involves a modification to the document with the relevant ID in the collection that observeLocal() 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 listen for changes that occur in relation to a document locally and to signal when you are ready for the live query to deliver the next event.

    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 also call subscribe() separately, using another findByID() call that references the same document ID.

    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: SingleObservationHandler

      A block that will be called every time there is a transaction committed to the store that involves a modification to the document with the relevant ID in the collection that observeLocal() 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 listen for changes that occur in relation to a document locally and remotely, and to signal when you are ready for the live query to deliver the next event.

    The handler closure will be called when local or remote changes are made to the document referenced by the findByID() call 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: SingleObservationHandler

      A closure that will be called every time there is a transaction committed to the store that involves a modification to the document with the relevant ID in the collection that observe() was called on.

    Returns LiveQuery

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

remove

  • remove(): Promise<boolean>
  • Removes the document with the matching ID.

    Returns Promise<boolean>

    true promise if the document was found and removed. false promise if the document wasn't found and therefore wasn't removed.

subscribe

  • Enables you to subscribe to changes that occur in relation to a document 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 the relevant document.

    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 the document.

update

  • update(closure: (document: any) => void): Promise<UpdateResult[]>
  • Updates the document with the matching ID.

    Parameters

    • closure: (document: any) => void

      A closure that gets called with the document matching the ID. If found, the document is a MutableDocument, so you can call update-related functions on it. If the document is not found then the value provided to the closure will be undefined.

        • (document: any): void
        • Parameters

          • document: any

          Returns void

    Returns Promise<UpdateResult[]>

    An array promise of update results that describe the updates that were performed on the document.