0

I am building an app using AstraDB with NodeJS. I love Cassandra and wanted to try it out for my application

Unfortunately, The Node Cassandra Driver seems not to perform well. Batch Operations are not working. delete operations are also not working. They work fine when I run them in AstraDB CQL console. Is there something I am not aware of?

1
  • So questions about building applications with the driver are probably better-suited to Stack Overflow. But we don't know what "not working" means. Is it throwing an error? Or are the operations failing silently? And does "not perform well" mean "slow?" Commented Aug 29, 2023 at 13:07

1 Answer 1

1

If you are using the CQL BATCH command in your application like this:

BEGIN BATCH
    INSERT INTO ... ;
    UPDATE ... ;
    DELETE ... FROM ... ;
APPLY BATCH;

then it wouldn't work since it is designed to be used with the cqlsh utility only.

In your app, you will need to use the Client.batch() API of the Node.js driver to execute batch statements. It takes an array of statements to execute in one atomic operation. Here is a sample code from the Node.js driver docs:

const query1 = 'UPDATE user_profiles SET email = ? WHERE key = ?';
const query2 = 'INSERT INTO user_track (key, text, date) VALUES (?, ?, ?)';
const queries = [
   { query: query1, params: [emailAddress, 'hendrix'] },
   { query: query2, params: ['hendrix', 'Changed email', 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
  });

Since you're new to Cassandra, I should point out that CQL batches should not be used for bulk-loading data since they are not an optimisation in the same way that batches are in relational databases. Only use CQL batches when you need to achieve atomicity for multiple partitions.

For the second part of your question, it's impossible to know what problem you are running into with DELETE operations because you didn't provide any detail.

A friendly reminder that you need to (a) provide a good summary of the problem that includes software/component versions, the full error message + full stack trace; (b) describe what you've tried to fix the problem, details of investigation you've done; and (c) minimal sample code that replicates the problem. If it helps, I wrote an article on Asking good questions published on the official Apache Cassandra website. Cheers!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.