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 {
transactions.run((ctx) -> {
ctx.insert(defaultCollection, documentId, jsonDocument);
ctx.commit();
});
} 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?