I have a Cassandra DB and am creating a column family as follows.
CREATE COLUMN FAMILY users
WITH comparator = UTF8Type
AND key_validation_class=UTF8Type
AND column_metadata = [
{column_name: username, validation_class: UTF8Type}
{column_name: city, validation_class: UTF8Type, index_type="KEYS"}
];
I am inserting data into the column family using the following in node.js
var cql = "INSERT INTO App.users(KEY,username,city) VALUES (?,?,?)";
cassandra.execute(cql,[json.username+(new Date().getTime()),json.username,
json.city], function(err, rows) {
if(err) {
console.log(err);
return 1;
}
return 0;
});
This executes properly, but suppose I use cassandra-cli and run
get user where city='NYC';
I get an unavailable exception. The following is the CQL query which I have in my node.js script which throws the same exception.
var cql = "SELECT notes,heading FROM App.users where city=?";
Do you have any idea what I am doing wrong? I have made a secondary index on the city column, I hope that is correct. Thanks in advance.
Thanks Abhi for your suggestion. The link was really helpful, so I created the keyspace in the following manner and it worked properly.
create keyspace App with placement_strategy ='org.apache.cassandra.locator.SimpleStrategy'
and strategy_options = {replication_factor:2};
I have connected 2 computers to my cassandra cluster, hence the replication_factor is set to 2.
Perhaps it is a keyspace creation issue. Check your keyspace creation schema properly. May be this discussion on cassandra user group will give you a better idea