1
votes

I am try to insert a record into cassandra-2.2.3 using datastax Node.js driver ([email protected]). Most of the cql operations work well, however below cql statement can't execute correctly. The driver continues respond "Cannot provide custom timestamp for conditional updates"?

var current = new Date();
var current_timestamp = current.getTime();
var userId = uuid.random();
var cqlStatement = "INSERT INTO user_credentials(email, password, userid) VALUES(?, ?, ?) IF NOT EXISTS USING TIMESTAMP ?";
var cqlParams = [user.emailAddress, user.password, userId, current_timestamp];

cassandra_client.execute(cqlStatment, cqlParams, { prepare: true }, function (err, result) {
        if (err) {
            var exception = new ttypes.UserManagementException() 
            exception.code = ttypes.UserManagementErrorCode.INTERNAL_ERROR;
            exception.reason = err.reason;
            callback(err); //tell client exception occurred
            return;
        }
        console.log("Execute correctly");}

Any one has encounter similar issue? Or any advise?

1

1 Answers

1
votes

You should provide the timestamp in the query options:

const cassandra = require('cassandra-driver');
//Long value representing microseconds from the unix epoch
const timestamp = types.generateTimestamp();
client.execute(query, params, { prepare: true, timestamp: timestamp}, callback);

generateTimestamp() takes 2 optional parameters (date and microseconds portion).