Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a auto incremented column in Documentdb

I want to create a document in azure documentdb with an auto-increment column.

Is this possible? If yes, please guide me.

Any help would be greatly appreciated.

Database db = CreateOrReadDocumentDb("EmployeeDb").Result;
DocumentCollection dc = CreateOrReadDocumentCollection(db.SelfLink, "EmployeeDetails").Result;
Employee emp = new Employee();
emp.Name="ABC";
emp.id="";//automatically generate a unique string
emp.sal=10000;
emp.exp =5;
emp.index=0; // I want an auto increment column for emp with name index and want to store in azure document db
 client.CreateDocumentAsync(collectionLink, data);
like image 522
satish kumar V Avatar asked Dec 30 '14 05:12

satish kumar V


1 Answers

DocumentDB doesn't include auto-increment functionality out of the box.

As Gaurav mentioned in Do we have Identity Column in DocumentDB, the id field is special in that if a value isn't provided by the application - DocumentDB will assign a GUID automatically.

If you need the auto-increment functionality, one potential solution would be to store a counter as a document and leverage DocumentDB's triggers to populate your field and update the counter.

like image 189
Andrew Liu Avatar answered Sep 26 '22 03:09

Andrew Liu