I am working on a method that saves to DynamoDB. I want the method to save if the value doesn't exist in the table. If it does exist, I want to apply a conditional update. I am using DynamoDBMapper's save method.
The code I have at the moment does the conditional save successfully, but throws an exception if the column doesn't exist in the database.
Is there a way to come up with a conditional update expression that checks if the value doesn't exist or checks for the condition I need?
The code I have at the moment, which is in Java, looks like this:
DynamoDBSaveExpression saveExpression = new DynamoDBSaveExpression();
AttributeValue attributeValue = new AttributeValue(valueToSave);
ExpectedAttributeValue expectedAttributeValue = new ExpectedAttributeValue(attributeValue).withComparisonOperator(ComparisonOperator.LT);
Map<String, ExpectedAttributeValue> expected = new HashMap<>();
expected.put("key", expectedAttributeValue);
saveExpression.setExpected(expected);
dynamoDbMapper.save(objectToSave);
Thanks!