dynamo
dynamo copied to clipboard
Incrementing a value
Hello,
How would you recommend I do something like this with this library:
dynamoDB.updateItem({
TableName: "Users",
Key: { "UserId": { S: "c6af9ac6-7b61" } },
ExpressionAttributeValues: { ":inc": {N: "1"} },
UpdateExpression: "ADD loginCount :inc"
})
I am currently fetching the row getting the value then adding 1 to it but I am worried about race conditions.
That is supported. Just do:
session.Table("tableName").Update("hashKeyName", hashKeyValue).Add("fieldToUpdate", 1).Run()
Replace Run with OldValue if you want to retrieve the old value