我正在尝试将JSon文档插入到azure cosmos db中,我的Json文档具有id列,并且具有字符串值。使用CreateItem函数将此JSONObject插入Cosmos DB时,它引发错误,提示“输入内容无效,因为必需的属性-'id;'-丢失”。下面是代码和示例JSONObject加载。可以帮忙吗?
query = "select * from <ks>.<tn>";
Statement st = new SimpleStatement(query);
ResultSet rows = session.execute(st.setFetchSize(1000));
Iterator<Row> it = rows.iterator();
while (it.hasNext()) {
if (rows.getAvailableWithoutFetching() == 100 && !rows.isFullyFetched())
rows.fetchMoreResults();
}
Row row = it.next();
JSONObject jsonObject = new JSONObject(row.getString("[json]"));
jsonObject.put("id",jsonObject.get("doc_id"));
CosmosItemRequestOptions cosmosItemRequestOptions = new
CosmosItemRequestOptions();
CosmosItemResponse<JSONObject> item = container.createItem(jsonObject, new
PartitionKey((String) jsonObject.get("doc_id")), cosmosItemRequestOptions);
}
Json文档示例:
{
"abc": null,
"year": 1996,
"name": "",
"num": null,
"anum": null,
"st": "mo",
"did": "1398",
"de": null,
"sq": null,
"dq": "",
"d":null,
"dpp": null,
"dif": null,
"dmf": null,
"dtc": null,
"id": "1398-48",
"day": null,
"dtc": null,
"drt": null,
"nr": null,
"daf": null,
"ds": null,
"da": null,
"andrf": null
}