Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Collection

Represents a collection of a Ditto store.

This is the entrypoint for inserting documents into a collection, as well as querying a collection. You can get a collection by calling collection() on a Store of a Ditto object.

Hierarchy

  • Collection

Index

Properties

Methods

Properties

Readonly name

name: string

The name of the collection.

Readonly store

store: Store

The store this collection belongs to.

Methods

find

  • Generates a PendingCursorOperation using the provided query.

    The returned object can be used to find and return the documents or you can chain a call to observe or subscribe if you want to get updates about the list of matching documents over time. It can also be used to update, remove or evict the matching documents.

    You can incorporate dynamic data into the query string with placeholders in the form of $args.my_arg_name, along with providing an accompanying dictionary in the form of { "my_arg_name": "some value" }. The placeholders will be appropriately replaced by the corresponding argument contained in queryArgs. This includes handling things like wrapping strings in quotation marks and arrays in square brackets, for example.

    Parameters

    • query: string

      The query to run against the collection.

    • Optional queryArgs: QueryArguments

      The arguments to use to replace placeholders in the provided query.

    Returns PendingCursorOperation

findAll

findByID

insert

  • Inserts a new document into the collection and returns its ID.

    Parameters

    • value: { id?: DocumentID; isDefault?: boolean; value: DocumentValue }
      • Optional id?: DocumentID

        The ID to use for the document. If null or undefined then Ditto will automatically generate an ID.

      • Optional isDefault?: boolean

        Whether or not the data being inserted should be treated as default data. Set this to true if you want to set a default value that you expect to be overwritten by other devices in the network. The default value is false.

      • value: DocumentValue

        The data for the new document to insert.

    Returns Promise<DocumentID>