Cassandra cql comparator type counter

I want to use the following code to update a field ...

@@db.execute("UPDATE user_count SET counters = counters + #{val} WHERE cid = 1 ")

The first time I tried, I got the following:
CassandraCQL :: Error :: InvalidRequestException: invalid operation for non-commutation columnfamily user_count
I found out that I need to use a comparator counter, but I can’t find how I can configure this using cassandra -cql gem ... does anyone know how I can make this work? below is my code that doesn't work ...

@@db.execute("CREATE COLUMNFAMILY user_count(cid varchar PRIMARY KEY, counters counter) with comparator = counter " )
@@db.execute("INSERT INTO user_count (cid, counters) VALUES (?,?)", 1, 0)
0
source share
1 answer

You need to set default_validation = CounterColumnType instead of the comparator.

@@db.execute("CREATE COLUMNFAMILY user_count(cid varchar PRIMARY KEY, counters counter) with default_validation=CounterColumnType")
@@db.execute("update user_count set counters = counters + 1 where cid = 1")

"", , ( CQL- , , ).

- ( wiki: " ." )

+2

All Articles