Readonly
nameThe name of the collection.
Readonly
storeThe store this collection belongs to.
Trigger an attachment to be downloaded locally to the device and observe its progress as it does so.
When you encounter a document that contains an attachment the attachment
will not automatically be downloaded along with the document. You trigger
an attachment to be downloaded locally to a device by calling this method.
It will report events relating to the attachment fetch attempt as it tries
to download it. The eventHandler
block may be called multiple times with
progress events. It will then be called with either a Completed
event or
a Deleted
event. If downloading the attachment succeeds then the
Completed
event that the eventHandler
will be called with will hold a
reference to the downloaded attachment.
An AttachmentFetcher
object, which must be kept alive for the
fetch request to proceed and for you to be notified about the attachment's
fetch status changes.
The AttachmentToken relevant to the attachment that you wish to download and observe. Throws if token is invalid.
Optional
eventHandler: ((event: AttachmentFetchEvent) => void)An optional callback that will be called when there is an update to the status of the attachment fetch attempt.
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 observeLocal()
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.
Find more information about the query string format in the documentation's section on Querying
The query to run against the collection.
Optional
queryArgs: QueryArgumentsThe arguments to use to replace placeholders in the provided query.
Convenience method, equivalent to calling find() and passing
the query "true"
.
Generates a PendingIDSpecificOperation with the provided document ID.
The returned object can be used to find and return the document or you can chain a call to observeLocal(), or subscribe() if you want to get updates about the document over time. It can also be used to update, remove or evict the document.
The ID of the document to find.
Creates a new Attachment object, which can then be inserted into a document. Node only, throws when running in the web browser.
The file residing at the provided path will be copied into Ditto's store. The Attachment object that is returned is what you can then use to insert an attachment into a document.
You can provide metadata about the attachment, which will be replicated to other peers alongside the file attachment.
Below is a snippet to show how you can use the newAttachment() functionality to insert an attachment into a document.
const attachment = await collection.newAttachment('/path/to/my/file.pdf')
await collection.upsert({ _id: '123', attachment, other: 'some-string' })
}
The path to the file that you want to create an attachment with or the raw data.
Optional
metadata: { Metadata relating to the attachment.
Inserts a new document into the collection and returns its ID. If the
document already exists, the contents of both are merged by default. You
can change this by providing a different writeStrategy
via options
.
The content of the document to be inserted or updated.
Optional
options: UpsertOptions
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.