4

How can I generate an autoincremented Id in a Cosmos DB if I do a POST request from Spring Boot.

Techie
  • 81
  • 1
  • 10

2 Answers2

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
0

Use @Id @GeneratedValue private String id;