Search code examples
ibm-cloudcloudant

What is cloudant document expiration field?


Is document expiration field set with date-time or seconds or milliseconds? As I know it's seconds:

"expiration": 1543086426,

So 1543086426 = Saturday, November 24, 2018 7:07:06 PM

Then why the document is being removed by Cloudant? If it's milliseconds then:

1543086426 =  Sunday 18 January 1970 12:38:06

that explains. So how do I set proper expiration value for cloudant document e.g. in 1 month from now?

Also, which Cloudant task is responsible for document removal? And how often it starts?


Solution

  • As pointed out in the CouchDB document

    Time to live (TTL) is the amount of time until a document expires in Couchbase Server. By default, all documents have a TTL of zero, which indicates the document is kept indefinitely. Typically when you add, set, or replace information, you establish a custom TTL by passing it as a parameter to your method call. As part of normal maintenance operations, Couchbase Server periodically removes all items with expiration times that have passed.

    Depending on the amount of time you want to specify for the document to live, you provide a TTL value as a relative number of seconds into the future or in Unix time . Unix time represents a specific date and time expressed as the number of seconds that have elapsed since Thursday, 1 January 1970 at 00:00:00 Coordinated Universal Time (UTC) . For example, the value 1421454149 represents Saturday, 17 January 2015 at 00:22:29 UTC.

    But, Cloudant does not support Time to Live functions.

    The reason is that IBM Cloudant documents are only 'soft' deleted, not deleted. The soft deletion involves replacing the original document with a smaller record. This small record or 'tombstone' is required for replication purposes; it helps ensure that the correct revision to use can be identified during replication.

    If the TTL capability was available in IBM Cloudant, the resulting potential increase in short-lived documents and soft deletion records would mean that the database size might grow in an unbounded fashion.

    For more info, refer this link on TTL