Question

Is there a way to update Cassandra database to update the table like in MySQL? I have data stored in cassandra and I need to update the data. Is there any update command to do so?

Était-ce utile?

La solution

Yes, you can perform an UPDATE (from the CQL shell) to a row in the database. However, unlike MySQL you can only specify the primary key(s) in the WHERE clause. This example assumes a table called "products" with a primary key of "productNumber."

UPDATE products
SET description1='PROD DESC1'
WHERE productNumber='ITEM00123';

If a row does not exist for the primary key you have specified, a new one will be created.

For more information, see the DataStax documentation on the UPDATE CQL command that abhi linked in his answer.

Edit: I'm not sure about pure Javascript, but there is a Cassandra driver (node-cassandra-client) for Node.js. You can use that driver to connect to Cassandra and peform an update in Javascript. Here's an example of how to perform the above UPDATE:

 var conOptions = { hosts: ['127.0.0.1:19170'],
                    keyspace: 'productKeyspace',
                    use_bigints: false };
 var con = new PooledConnection(conOptions);
 var cql = 'UPDATE products SET description1=? where productNumber=?';
 var params = ['PROD DESC1', 'ITEM00123'];
 con.execute(cql, params, function(err) {
   if (err) {
     console.log(err);
   }
   con.shutdown(callback);
 });

For more information, check out Rackspace's doc on the node.js driver.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top