I am trying to insert a JSon document into azure cosmos db, My Json document has and id column existing with string value. While inserting this JSONObject to Cosmos DB using CreateItem function but it throws error saying "The input content is invalid because the required properties - 'id; ' - are missing". Below is the code and sample JSONObject loading. Can some one help?
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);
}
Sample Json doc:
{"abc":null,"year":1996,"name":"","num":null,"anum":null,"st":"mo","did":"1398","de":null,"sq":null,"dq":"","d":nrull,"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}