我尝试使用datastax Node.js驱动程序(cassandra-driver@2.2.2)将记录插入cassandra-2.2.3。大多数cql操作都运行良好,但是下面的cql语句无法正确执行。驱动程序继续响应“无法为条件更新提供自定义时间戳”?
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");}
有人遇到类似问题吗?或者任何建议?
答案 0 :(得分:1)
您应该在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()
需要2个可选参数(日期和微秒部分)。