Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override id creation in Azure cosmos DB

I have a JSON document, which I need to push to azure cosmos db. I am using DocumentDB data migration tool to dump my json file to azure cosmos DB. The problem is my JSON contains an id field which is same for all the records. For e,g.

"angularAcceleration_T12_x:-0.137993,"id":"5946001","jointAngle_jRightHip_z"

And because of this id field, I am not able to insert more than 1 record in my collection as after inserting one record I get an error message "resource with specified id already exist". Is there a way to force cosmos DB to ignore the id field in JSON and create a GUID for each entry, like it does if it does not find an id field.

Thanks, Yaju

like image 260
yaju Avatar asked Jan 30 '18 08:01

yaju


People also ask

Is ID mandatory in Cosmos DB?

Every resource within an Azure Cosmos DB database account needs to have a unique identifier.

Does Cosmos DB auto generate ID?

CustomerID properties contain the same value in the Cosmos document, it's unlikely that bugs will occur in code regardless of which property is used. However, if the Customer.ID is an auto-generated GUID and the Customer.

Is ID a good partition key?

The item ID is a great partition key choice for the following reasons: There are a wide range of possible values (one unique item ID per item). Because there is a unique item ID per item, the item ID does a great job at evenly balancing RU consumption and data storage.


1 Answers

After a lot of searching i came to the verdict that if you have a column named "id"(case sensitive) in your json, cosmos db will be make that column value as the id for the document, you can not use any other column as the unique identifier. If cosmos does not find id field, it will create a GUID as the id for the document.

like image 193
yaju Avatar answered Oct 04 '22 02:10

yaju