How can I generate an autoincremented Id in a Cosmos DB if I do a POST request from Spring Boot.
Asked
Active
Viewed 3,562 times
4
-
Cosmos DB does not have support for autoincrement. You will need to implement this yourself. – Mark Brown Nov 08 '20 at 19:44
-
Is there any reference for it. – Techie Nov 09 '20 at 13:02
-
Why would there be docs on something that is not supported? – Mark Brown Nov 09 '20 at 15:54
2 Answers
1
The docs explain the behavior here: https://github.com/Azure/azure-sdk-for-java/tree/master/sdk/cosmos/azure-spring-data-cosmos#spring-data-annotations
public class GeneratedIdEntity {
@Id
@GeneratedValue
private String id;
}
As mentioned, Cosmos uses UUIDs rather than an auto-increment long.

avolkmann
- 2,962
- 2
- 19
- 27