The name of the collection.
The 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 onFetchEvent
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 callback
will be called with will hold a
reference to the downloaded attachment.
The AttachmentToken relevant to the attachment that you wish to download and observe. Throws if token is invalid.
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 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.
The query to run against the collection.
The 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 observe(), 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. If not an instance of DocumentID then Ditto will automatically create a DocumentID instance from it.
Inserts a new document into the collection and returns its ID.
The content for the new document to insert.
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 = collection.newAttachment('/path/to/my/file.pdf')
const docID = new DocumentID('123')
collection.insert({ _id: docID, attachment, other: 'some-string' })
}
The path to the file that you want to create an attachment with or the raw data.
Metadata relating to the attachment.
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.