I am trying to insert item if it does not exist and set its counter to 1 or increment counter by one when it exists but it doesn't seem to work...
Here is what I have done so far:
UpdateItemSpec updateItemSpec = new UpdateItemSpec()
.withPrimaryKey("Id", Id)
.withReturnValues(ReturnValue.ALL_NEW)
.withUpdateExpression("set #c = if_not_exists(#c = :val, #c + :val)")
.withNameMap(new NameMap()
.with("#c", "counter"))
.withValueMap(new ValueMap()
.withNumber(":val", 1));
when I change the update expression to set #c = #c + :val
it updates existing items but it doesn't insert new item if it does not exist.
set #c = :val
seems to work on both exist and not exist but that's not what I need.