Sac*_*hin 5 cassandra node.js datastax
我在 cassandra 中有一个非常简单的表。
名称: 测试
列:
我正在尝试使用nodejs(使用cassandra-driver)将值插入其中
client.execute("insert into test (id, name) values (?, ?)", [123, "dskddjls"], function (err, response) {
if (err) {
console.log("An error occured, ", err)
//...
}
else {
console.log("Added to table, ", response)
//...
}
})
Run Code Online (Sandbox Code Playgroud)
插入成功完成,但当我检查我的 cassandra 数据库时,似乎大 int 列有垃圾值。
有什么解释为什么会发生这种情况吗?
您需要明确指定类型作为execute函数的第三个参数:
client.execute("insert into test (id, name) values (?, ?)", [123, "dskddjls"], {hints: ["bigint", null]}, function (err, response) {
...
})
Run Code Online (Sandbox Code Playgroud)
原因是对于某些字段,cassandra 驱动程序无法猜测类型(如 bigint 或 timestamp),因此您需要提示它。对于字符串或常规数字,它将在没有提示的情况下工作。
| 归档时间: |
|
| 查看次数: |
2237 次 |
| 最近记录: |