Document Expiration not working with Transaction

Hi Team,

I am using Transaction Object to create some documents and I need to set the expiration for the document to be set as 3 days.

I have attached the code snippet below.

	public static void main(String[] args) {
		Cluster cluster = Cluster.connect(host, userName, password);
		Bucket bucket = cluster.bucket(bucketName);
		Collection defaultCollection = bucket.defaultCollection();

		Duration expiry = Duration.ofDays(3l);
		TransactionConfig config = TransactionConfigBuilder.create().expirationTime(expiry).build();

		Transactions transactions = Transactions.create(cluster, config);
		String documentId = "test123#" + System.currentTimeMillis();
		JsonObject jsonDocument = JsonObject.create().put("name", "name1").put("age", 22).put("type", "emp");

		try { -> {
				ctx.insert(defaultCollection, documentId, jsonDocument);
		} catch (TransactionCommitAmbiguous e) {
			System.err.println("Transaction possibly committed");
		} catch (TransactionFailed e) {
			System.err.println("Transaction did not reach commit point");

It seems to work but its not setting the expiration as I expect it to be.

Can someone tell me what I am doing wrong?

Hi @Manzoor128,

Setting document expiration times is not currently supported in the transactions library. And any document you read inside a transaction that has an expiration time, will have that expiration time reset if you mutate that document inside the transaction. E.g. it will no longer expire.

This might be something that changes in the future - we are certainly monitoring feedback like this to see if this is a feature that our users want. But it is not on the immediate roadmap.

(The expirationTime option on TransactionConfigBuilder is a timeout that controls the expiration time of the overall transaction, not the documents in it. )