(meta-note @prasads697: it might be better to create a new topic rather than pick up a really old one for new questions)
There are a couple options here:
First, if you need to use this programmatically, not just for development time observability, starting with Couchbase Server 5.0, there is a feature named virtual xattrs that allows you to retrieve a number of these metadata fields. This is covered in the documentation on XATTRs. If you have questions after reading the docs I’d encourage you to click the “Feedback” button there.*
Second, if you just need to verify what is occurring with a given doc at development time, the libcouchbase cbc tools make this quite easy to do. There is a cbc keystats
utility that can give you statistics about that particular document or you can use the subdocument API from cbc.
You can use the cbc utility included in libcouchbase to fetch the TTL with --keystats. For example:
$ cbc-stats --keystats -u Administrator -P - -U couchbase://localhost/travel-sample airline
_112
Bucket password:
localhost:11210 key_is_dirty false
localhost:11210 key_exptime 0
localhost:11210 key_flags 33554432 (cbc: converted via htonl)
localhost:11210 key_cas 1503621971151421440
localhost:11210 key_vb_state active
Or an example that accesses the virtual xattrs:
$ cbc-subdoc -u Administrator -P - -U couchbase://localhost/travel-sample
Bucket password:
subdoc> get -x $document airline_112
airline_112 CAS=0x14ddf0375af40000
0. Size=188, RC=0x00 Success (Not an error)
{"CAS":"0x14ddf0375af40000","vbucket_uuid":"0x0000e976b253ad5c","seqno":"0x0000000000000001","exptime":0,"value_bytes":118,"datatype":["json"],"deleted":false,"last_modified":"1503621971"}
1. Size=118, RC=0x00 Success (Not an error)
{"callsign":"FLYSTAR","country":"United Kingdom","iata":"5W","icao":"AEU","id":112,"name":"Astraeus","type":"airline"}
subdoc> get -x $document.exptime airline_112
airline_112 CAS=0x14ddf0375af40000
0. Size=1, RC=0x00 Success (Not an error)
0
1. Size=118, RC=0x00 Success (Not an error)
{"callsign":"FLYSTAR","country":"United Kingdom","iata":"5W","icao":"AEU","id":112,"name":"Astraeus","type":"airline"}
subdoc> get -x $document.exptime -x $document.value_bytes airline_112
airline_112 CAS=0x14ddf0375af40000
0. Size=1, RC=0x00 Success (Not an error)
0
1. Size=3, RC=0x00 Success (Not an error)
118
2. Size=118, RC=0x00 Success (Not an error)
{"callsign":"FLYSTAR","country":"United Kingdom","iata":"5W","icao":"AEU","id":112,"name":"Astraeus","type":"airline"}
Finally, I’d note that over the years we’ve had people occasionally report that the expiry wasn’t being honored when being set by the app, but to my knowledge in all cases that’s been reported we’ve found a bug in the app using our SDK’s lib. There certainly could be an issue and if you can extract a simple test case, we’d be glad to look at it. Expiration handling has been in Couchbase since day one and is tested regularly, so I suspect the issue is probably elsewhere.
Oh, and by the way, note that expiration is always converted from offsets to absolute at the time of receipt. So if you set something like 300 seconds, it’ll actually show in the value as (epoch_time+300s).
* and note there is a documentation request pending of @Richard_Smedley to improve the documentation, which the ticket DOC-3221 says is in progress