Search code examples
node.jscassandracqlcassandra-3.0

Invalid unset value for column id


I want to update a record that may or may not exist. If it doesn't exist then nothing should happen.


I am using cassandra driver for node, getting the error

UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): ResponseError: Invalid unset value for column question_id

When trying to do something like

let question = {
  question_part: ['How many times has Leicester Tigers won the Heineken Cup?'],
  answer: ['2'],
  tags: ['competition', 'rugby'],
  title: 'Rugby pub quiz'
};

let query = 'update question set answer = ?, question_part = ?, tags = ?, title = ? where question_id = ?';
const params = [question.answer, question.question_part, question.tags, question.title, question.question_id];
cassandraClient.execute(query, params, {prepare: true});

On a table like

CREATE TABLE question (
    question_id timeuuid PRIMARY KEY,
    answer list<text>,
    cakes int,
    created timestamp,
    creator_display_name text,
    creator_id text,
    difficults int,
    dislikes int,
    drops int,
    easies int,
    favorites int,
    impossibles int,
    last_activity timestamp,
    likes int,
    question_part list<text>,
    right_answers int,
    tags set<text>,
    title text,
    views int,
    wrong_answers int
)

Solution

    1. Update your question definition to include question_id.
    2. Update your query to include parameter for title 'update question set answer = ?, question_part = ?, tags = ?, title = ? where question_id = ?'