Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started

 

question

ssnmurtyraju_188715 avatar image
ssnmurtyraju_188715 asked ·

CosmosDB throws "The input content is invalid because the required properties - 'id; ' - are missing" error

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}

cosmos dbunsupported
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

Erick Ramirez avatar image
Erick Ramirez answered ·

@ssnmurtyraju_188715 I'm not an expert on Cosmos DB but as I understand it, it provides a CQL-like API to users but it isn't a full-fledged Apache Cassandra database under the hood so I'm afraid we can't troubleshoot your problem.

I recommend you instead try DataStax Astra -- a cloud-native Database-as-a-Service that's built on Apache Cassandra. It's FREE to try and you don't need a credit card to sign up. It only takes a few clicks to launch a Cassandra cluster. Try running your app on it to see if it works. Cheers!

Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.