【发布时间】:2016-04-21 14:55:08
【问题描述】:
我想将 json 文件从本地系统存储到 cassandra 列,因为新版本的 cassandra 支持 json 数据。对于解决方案,我正在寻找这样的方法:-
globalvariable<-load json file from local system.
cassandracolumn<-dump(globalvariable)
third thing i want to know the type of cassandracolumn, so that is support,
entire json data, whether it is text or blob.
我不知道这是否可能。非常感谢您的建议。我在 ubuntu 14.04 lts 系统上使用 cassandra2.2.4。
I tried so far:
1.var data = params.jsonData; //assign entire json data to variable
2. var insertQuery = "INSERT INTO " +keyspace+ "."+table_name+ " JSON
'{"+data+"}';";
console.log(insertQuery);
client.execute(insertQuery, function(err, result2){
if(result2){
return res.json("data inserted");
}
else{
return res.json("data insertion failed");
}
});
我在准备 insertQuery 时做错了。
On console log : INSERT INTO jsondb.iris JSON '{[object Object]}';
Response : “data insertion failed”
application: rest API creation
我没有将 json 数据直接传递给 cassandra,但在我的情况下,我必须通过 rest API 正文部分传递 jsondata。所以我必须收集整个 json 数据,然后转储到 cassandra 列中
【问题讨论】:
-
看起来
jsonData是一个对象而不是字符串,INSERT INTO table JSON ?需要一个字符串。如果您有一个具有类型值的对象,您可以编写完整的查询:INSERT INTO table (col1, col2, col3, ...) VALUES (?, ?, ?, ...)并使用jsonData的属性作为参数。 -
JSON.parse 会,我认为是正确的包。但无法通过 npm registery 安装。通过 JSON.parse(整个 json 对象),我们可以分配给一些变量..然后将该变量转储到 cassandra 列中......任何人都可以建议我在我的节点项目中的 ubuntu 14.04 lts 中安装 JSON.parse 的命令。
标签: javascript node.js cassandra