This article provides information on removing documents within Ditto.
DELETE
ensure that devices running Ditto Edge SDK are on version 4.10.1 and later.For more information on how to use delete and manage data reach out to Ditto’s Customer SupportDELETE
keyword in DQLEVICT
keyword in DQLDELETE
when you want to permanently remove a document from a collection. Once a document is deleted with DELETE
,
it is considered gone from the user’s perspective and cannot be recovered.EVICT
when you want to remove data only from the local device. Evictions are useful for scenarios where an Edge SDK
only needs to store and sync part of the database. Evicting a document doesn’t delete it from the system — it just frees up local storage.DELETE
to manage permanent deletion on Ditto Server.EVICT
to manage data on a Ditto Edge SDK.DELETE
keyword in DQL permanently removes one or more specified documents from the Ditto system. Once deleted these
document are non-recoverable.
DELETE
DELETE
condition will be permanently deleted. The ids of deleted document can be referenced
using the mutatedDocumentIDs
method on the result
.
The following example permanently deletes all blue
cars stored in the cars
collection:
DELETE
DELETE
will permanently remove the selected documents from the system.reaper_preferred_hour
and enable enable_reaper_preferred_hour_scheduling
to ensure
minimal business impact.reaper_preferred_hour
expired tombstones will not be evicted.DELETE
query through the HTTP API.
For information on how to execute a DQL query through the HTTP API see HTTP POST API > Execute a DQL query
Considerations when Deleting through Ditto Server
DELETE
statement performed on the Cloud/Server through the HTTP API are executed immediately as a single atomic operation. Removing a larger number
of documents (approx. 50,000 or more) at once has the risk of causing performance impact to the larger system. Performance impacts includes
slow sync times for all connected SDK Edge devices. To minimize potential impact it’s recommended to delete documents in batches of 30,000 or less.
This can be done using the LIMIT
keyword._id
) and metadata about the document including the time the document was deleted (deletion timestamp).
Document tombstones have a deletion timestamp. Once the timestamp goes beyond the set time to live (TTL) the document
tombstone is considered expired and will be removed in a process called the tombstone reaping. Tombstone
reaping is where the Ditto system scans for and removes expired tombstones. Tombstone reaping runs once daily
by default.
Document tombstones by default are retained on Edge SDK devices for 7 days before being automatically removed.
The Ditto system keeps document tombstones around ensures all peers are aware of the deleted document. Once the document
tombstone is removed from the system there will be no history of the document’s existence.
Configuring Document Tombstone Retention on the Edge SDK
Ditto offers a set of 5 system properties for configuring tombstone retention on a Edge SDK. All properties can be
enabled using the ALTER SYSTEM
command on a Edge SDK device. For help configuring a retention policy that’s best
for your use case reach out to Ditto’s Customer Support
Default configuration:
disabled
. To enable set system parameter TOMBSTONE_TTL_ENABLED
to true
.EVICT
method, once invoked, immediately removes the specified document(s) from the local Ditto store, making it inaccessible by local queries.
For complete DQL syntax, see EVICT.
Although the document you evicted is removed from the local Ditto store, the document stored within remote Ditto stores persists.
To prevent the evicted data from immediately reappearing on the screen, make sure to stop subscriptions before you call EVICT; otherwise, the subscription remains active and even if you reset the data in your end-user environment, the evicted data reappears as soon as the subscription sees it missing.
The EVICT
keyword in DQL immediately removes one or more specified documents from the local Ditto store, making it inaccessible by local queries.
EVICT
EVICT
condition, will be evicted. The ids of evicted document can be referenced using the mutatedDocumentIDs
method on the result
.
The following example evicts all blue
cars stored in the cars
collection from the local Ditto store:
'blue'
cars and you subsequently evict a document with the ID '123456'
that matches the replication
query, connected peers will notice that you are missing document '123456'
that matches your subscription for 'blue'
cars and send it back to you. To prevent this
from happening you need to ensure that any active sync subscriptions don’t contain documents you plan on evicting from the device.
isArchived
field value to true
:
NOT
* *archived, establish a live query where isArchived
is set to false
, and then construct your live query callback.
It’s likely that the isArchived
field is set lazily (i.e. has no value until it is true
), so you can use the coalesce()
function to automatically return false
if the value is unset.
The following code demonstrates searching for documents that are unarchived:
isArchived
field to false
: