Reputation: 217
I am new to cassandra (started learning on my own interest few days back) and looking for help for the below problem.
I have a Cassandra table "User" and a ListColumn "interests extends ListColumn[String]". Now, I want to fetch all users with an interest, say "playing".
like: select from user where interests.contains("playing")! I scanned through the ListColumn api but not able to find any. Also, searched in google but no such helpful posts.
Any help guys please... Thanks in Advance :)
Upvotes: 0
Views: 385
Reputation: 28511
This is possible with a secondary index on a collection column, which only works with a Set
column, and not with a List
.
Bottom line:
object interests extends SetColumn[String](this) with Index[Set[String]]
And then you can execute the following:
select.where(_.interests contains "test").fetch()
You can also use multiple restrictions if you allow filtering.
select.where(_.interests contains "test")
.and(_.interests contains "test2")
.allowFiltering()
.fetch()
The above will only match if both interests are found in a record.
Upvotes: 1
Reputation: 2500
So there is contains
among operators and here is an example how to use it. It looks like that it should work as any other operator, so just go for database.userTable.select.where(_.interests contains "playing").fetch()
- of course, depending on your conventions.
Upvotes: 1