Identity Column in DocumentDB

Sandip Bantawa picture Sandip Bantawa · Nov 2, 2014 · Viewed 9.9k times · Source

Is it possible to have identity column in documentDB for autoincrement, it's usually handy for IDs? Any link or hint relating to it can be useful.

Thanks.

Answer

Stopped Contributing picture Stopped Contributing · Nov 2, 2014

AFAIK, DocumentDB does not have this kind of concept. Each document in DocumentDB has an id property which uniquely identifies the document but that id field is of type string. When creating a document, you may choose not to specify a value for this field and DocumentDB assigns an id automatically but this value is a GUID. Thus if you wish to achieve auto increment type functionality, you would need to handle this on your own. However please do keep in mind that it is a string type property so even if you're handling this on your own, you would need to pad your string with zeros so that values are returned in proper order i.e. 1, 2, 3 etc. instead of 1, 10, 11, ... 19, 2, 20 ....