cassandra使用对象数组作为json插入

时间:2018-07-06 08:47:41

标签: json cassandra

当前在cassandra文档中,它说可以正常工作:

INSERT INTO cycling.cyclist_category JSON '{
  "category" : "GC", 
  "points" : 780, 
  "id" : "829aa84a-4bba-411f-a4fb-38167a987cda",
  "lastname" : "SUTHERLAND" }';

有什么办法可以轻松获得这样的东西吗?

INSERT INTO cycling.cyclist_category JSON '[{
  "category" : "GC", 
  "points" : 780, 
  "id" : "829aa84a-4bba-411f-a4fb-38167a987cda",
  "lastname" : "SUTHERLAND" }, {
  "category" : "GC", 
  "points" : 780, 
  "id" : "829aa84a-4bba-411f-a4fb-38167a987cda",
  "lastname" : "SUTHERLAND" }]';

通知数组。

1 个答案:

答案 0 :(得分:3)

您可以编写一个Python脚本,该脚本使用Cassandra驱动程序遍历数组并插入每个值。

session = cluster.connect()
arr = [..]
for data in arr:
  session.execute("INSERT INTO cycling.cyclist_category JSON " + json.dumps(data));