1

Cosmos DB, unlike SQL, doesn't support auto-incremental field. Any alternative for this?

user1472423
  • 101
  • 1
  • 12
  • 1
    @rickvdbosch It's close enough to a duplicate but probably not one. This one it talking about any field not just the id property. – Nick Chapsas Feb 01 '19 at 11:43
  • @NickChapsas - this has also come up in other near-identical questions as well. I closed as duplicate, and could have chosen others, such as [this one](https://stackoverflow.com/questions/54306418/how-to-handle-multiple-requests-simultaneously-in-java#comment95513255_54306418), which talk about creating new id's and avoiding duplicates (and is probably closer to a duplicate than the one chose, but unfortunately no way to un-close and re-close that I know of...). There are more as well - I just don't have time to hunt them down. – David Makogon Feb 01 '19 at 12:44

1 Answers1

1

No and the reason why mostly has to do with consistency levels, partitioning and global distribution.

It would require you to enable strong consistency which is very taxing in terms of money and performance and cross partition for the latest value of the field which would also be very bad for performance and RU/s reasons.

If you only had one instance of an app running with Cosmos DB as it's data store you could in theory do that by having the application handle that but this would be a very bad idea and I would also argue that you don't need Cosmos DB in the first place if you only have one instance of a service targeting it.

Nick Chapsas
  • 6,872
  • 1
  • 20
  • 29
  • Do you have recommended alternatives for CosmosDB in Azure if you have one instance of a service? – nrofis Oct 22 '20 at 19:35