简体   繁体   中英

How to set the consistency level in Cassandra using node.js driver?

I use node.js version 6.9.2 and Cassandra 3.9.

I would like to set a consistency level of LOCAL_QUORUM for all my queries when creating the Client instance.

According to this documentation , I need to do like the following.

const client = new Client({ queryOptions: { consistency: types.consistencies.quorum } });

I changed the consistency level of quorum to local_quorum.

const client = new Client({ queryOptions: { consistency: types.consistencies.local_quorum } });

However, when I start my app with this snippet of code, I receive an error.

ReferenceError: types is not defined

So, without fully understanding this meaning, I set text in place of types.

const client = new Client({ queryOptions: { consistency: text.consistencies.local_quorum } });

I received another error.

ReferenceError: text is not defined

My questions are:

What should be the value of types ?

Is changing the quorum to local_quorum necessary to have the consistency level of LOCAL_QUORUM? If it isn't, what is the correct way to assign LOCAL_QUORUM to my queries?

The type consistency is suppose to be types.consistencies.localQuorum if i remember correctly :)

Adding more info: The types is Inside the driver requirement to access it you need to declare it before

const cassandra = require('cassandra-driver');
const client = new cassandra.Client({ contactPoints: ['host1'] });
client.connect(function (err) {
  assert.ifError(err);
  client.execute(query, params, { consistency: cassandra.types.consistencies.localQuorum }, function (err) {
      //This callback will be called once it has been written in the number of replicas
      //satisfying the consistency level specified.
    });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM