Hi All,
I have a requirement as described below. For example, the application creates the JSON document shown below, which contains multiple sub-documents, each with a defined expiry/TTL. I want to delete a sub-document if it has expired (expiry < current time). How can I achieve this? If I use the DCP client, there will be significant data transfer between the application and the database. I am looking for an efficient solution.
Hi @creddym - couchbase document expiry is on whole documents. It looks like you’ve implemented your own expiry on subdocuments. You could find documents with expired sub-docs by periodically running a n1ql query, and then for every result, issue a mutateIn to delete the expired sub-docs.
@creddym yes as Michael says, it’s not directly supported (I don’t know of any document database that will automatically remove specific chunks of a document on a TTL in fact).
Personally I would look at refactoring the model so that each sub-object you want to have a TTL becomes a standalone document.