How do we increment atomic values?
Closed this issue · 1 comments
I couldn't find anything regarding updating a single value through incrementing or decrementing
user_table{
id
likes
}
Eg : likes+1 or likes-1
If I do this operation as getting() value then update() , what happens if another user tries to update in at the same time and my update happens on the value I got before other user's update and only after the other user did update.
Eg :
User1 GET (data : like=0)
User2 GET (data : like=0)
User1 UPDATE (data : like=1)
User2 UPDATE (data : like=1)
Finally like=1 instead of 2
??
The document API doesn't currently expose any incrementing functions (right now, it only has $push and $pop for arrays). Cassandra tables do support the counter
type, so you can create a table with one using the rest
package and increment it from there. Here's some documentation on that: https://docs.datastax.com/en/astra/docs/getting-started-with-datastax-astra.html