Using this way
const client = new cassandra.Client({ contactPoints: ['127.0.0.1'], localDataCenter: 'eu-west-3', keyspace: 'test',
});
const query1 = 'INSERT INTO user_track (key, text, date) VALUES (?, ?, ?)';
const query2 = 'INSERT INTO user_track (key, text, date) VALUES (?, ?, ?)';
const queries = [
{ query: query1, params: ['hendrix1', 'Changed email1', new Date()]},
{ query: query2, params: ['hendrix2', 'Changed email2', new Date()] }
];
// Promise-based call
client.batch(queries, { prepare: true })
.then(function() {
// All queries have been executed successfully
})
.catch(function(err) {
// None of the changes have been applied
});
Inserting only one row..
My expectation is to insert all rows.
Ok, so I'm curious to know what your underlying table
user_tracklooks like.Based on what you described, I did a
npm install cassandra-driver, started Cassandra locally, and created myuser_tracktable like this, withkeyas myPRIMARY KEY:I then ran your code, and I have two rows:
Here's my Git repo, if you'd like to have a look: https://github.com/aar0np/nodejsCassandraTest/tree/main
So everything looks correct from a code standpoint. Maybe reverify that you're on the latest version of the Nodejs cassandra-driver?