Getting TTL value from the existing document which is having some non-zero TTL value


#1

Hi,
I am setting TTL to a document while document creation(using UNIX time stamp), Next onward while upserting the document I want set the same UNIX time stamp as TTL . But I am wondering how to get the existing TTL value of a document using SDK.

While doing get operation the expiry(TTL) value is returned as zero, though the TTL is set as some value.

    int expiry = (int)Instant.now().getEpochSecond() + 20;
 	System.out.println("expiry: " + expiry);
 	
 	JsonDocument document = JsonDocument.create("112237", expiry, value) ;
 	bucket.insert(document);
 	
 	Thread.sleep(10000);
 	JsonDocument doc1 = bucket.get("112237");
 	System.out.println("expiry after insert: " + doc1);

output:
expiry: 1532329774
expiry after insert: JsonDocument{id=‘112237’, cas=1532329754485850112, expiry=0, content={“name”:“Test”,“interests”:“Test”}, mutationToken=null}

The use case here is From my application I will decide TTL value while inserting the document. In a later time application will do a get and try to update the same TTL value to the document(At this point of time I dont have any information about the TTL which was set previously).

Please help on this.

Regards
Paresh