Can we create an auto increment number sequence on Azure Cosmos Mongo DB API?
Asked
Active
Viewed 268 times
0

David Makogon
- 69,407
- 21
- 141
- 189

Swapnil
- 5
- 2
-
MongoDB does not have out-of-the-box auto increment functionality, like SQL databases. Check this reference document it may helps https://data-flair.training/blogs/mongodb-auto-increment-sequence/ – vijaya Nov 17 '22 at 16:06
-
@vijaya - that article suggests a JS function resulting in a single-point bottleneck. – David Makogon Nov 17 '22 at 21:50
-
There is no auto-increment. And this has been discussed in other questions as well, such as [this one](https://stackoverflow.com/q/54478715/272109). I suggest looking into guids, to remove all of the problems related to this. – David Makogon Nov 17 '22 at 21:52
1 Answers
0
No, unlike SQL databases that have this functionality natively, NoSQL databases don't let you create a auto incremental field.
You could create a query to select all the items in the collection and just use it the amount of documents that were returned. I don't think it would have a good performance when your solution reach out a big amount of data, but it could work temporarily.

Pedro Ignacio
- 23
- 2