6
votes

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

2

2 Answers

15
votes

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.

8
votes

Microsoft.Azure.Documents.Resource.Id documentation hints that it is serialised in JSON with fixed name "id":

[Newtonsoft.Json.JsonProperty(PropertyName="id")]
public virtual string Id { get; set; }

So, I would say that you cannot use another property as storage PK.

What you CAN do, is convert your JSON document yourself, for example renaming your current id to originalId or similar. Then documentDB would generate unique ids on import for you.