Search code examples
node.jscassandracassandra-driver

Nodejs - Apache Cassandra (using Datastax Driver)


I'm trying to insert a map type in cassandra:

const query = 'INSERT INTO stats.tickets (office, line, generation, inserted_at, meta, number, prefix) VALUES (:office, :line, :generation, :inserted_at, :meta, :number, :prefix)';

const parametersExample = {
    office: "office",
    line: "line",
    generation: 10,
    inserted_at: Date.now(),
    meta: {"tag1": "ujkukkik", "tag2": "asdascee"},
    number: 1,
    prefix: "prefix_"
};

const result = async () => {
    return await client.execute(query, parametersExample, { prepare: true });
};

result().then( res => {
    res.rows.map( row => console.log(row.content) );
    process.exit();
}).catch( err => console.error(err));

The code insert the row but shows the following message:

TypeError: Cannot read property 'map' of undefined
at lib/handleData.js:23:14
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:228:7)

What is the reason?


Solution

  • That's normal behavior - per CQL documentation:

    INSERT returns no results unless IF NOT EXISTS is used.

    So driver receives undefined... Usually .map will be used for selects.