Insert or upsert with TTL don't seem to set document expiration



Hi there,

Not sure if it’s a bug or I’m doing something wrong.

If I do this:

bucket.insert(document, expiry, TimeUnit.SECONDS);

Or this:

bucket.upsert(document, expiry, TimeUnit.SECONDS);

The created document always have the meta attribute expiration set to zero.

However if I touch the document after it has been created the expiration is set correctly, for example:

bucket.insert(document, expiry, TimeUnit.SECONDS);
bucket.touch(docId, expiry);

FYI I’m using Couchbase Java SDK 2.5.6.

Any clarification in this regard would be much appreciated.

Many thanks & regards.


Looks like you’re setting the timeout and not the expiry, i.e. the amount of time to wait for a response to the insert() call. See here:

By contrast, you can set the expiry as part of the Document object itself:

Because you don’t pass a Document into touch(), it does take expiry as a parameter, which is why that was working for you:


Understood, the problem is that I stupidly confused timeout with expiry, my bad.

However thanks for pointing out the possibility of setting the expiration as part of the document itself, because it will help me to create the document with expiration in a single step (which, by the way, is what I’d like to accomplish).

Many thanks for your help!


No problem, glad to help! Definitely made the same mistake myself a few times ;)…