masumsoft / express-cassandra

Cassandra ORM/ODM/OGM for NodeJS with support for Apache Cassandra, ScyllaDB, Datastax Enterprise, Elassandra & JanusGraph.
http://express-cassandra.readthedocs.io
GNU Lesser General Public License v3.0
232 stars 68 forks source link

Multiple value in $CONTAINS for SET data type #170

Closed dpkcse closed 6 years ago

dpkcse commented 6 years ago

need to set multiple value in contains for custom query now allowed only single value.

masumsoft commented 6 years ago

@dpkcse AFAIK, cassandra does not support OR relations in CONTAINS and CONTAINS_KEY operations for indexed collections. Otherwise please let me know your corresponding cql query that you wanna perform here.

https://docs.datastax.com/en/cql/3.3/cql/cql_reference/cqlSelect.html

dpkcse commented 6 years ago

Thanks for your reply. i got my solution already and know this rules but using AND i can set multiple value in CONTAINS and use execute_query() method for raw query instead of find().

var query = "SELECT * FROM Person WHERE col CONTAINS ? AND participants CONTAINS ? ALLOW FILTERING"; var params = [val1,val2]; models.instance.Person.execute_query(query, params, function(err, people){ //people is an array of plain objects });

masumsoft commented 6 years ago

@dpkcse As I can see from your query, you actually want contains on different columns not on the same column. To do that you should be able to use find like the following:

//Find all persons where my_set contains my_value
models.instance.Person.find({
    col: {$contains: val1},
    participants: {$contains: val2},
}, {raw: true}, function(err, people){

});