Azure Cosmos SQL API - How do I store a custom object as @PartitionKey

Viewed 292

Is it possible to store a custom POJO as a Json String using @PartitionKey using Java 8.? Is yes, please tell me how .

import com.azure.spring.data.cosmos.core.mapping.PartitionKey;

    @PartitionKey
        private Result result;

result will have value like {"resultID":"1","secret":"my secret"}

1 Answers

As rightly commented by @Mark Brown, I figured that - "It is not possible to specify an object as your partition key in Cosmos DB" , however I did a nested partition key path , like so:

import com.azure.spring.data.cosmos.core.mapping.Container;

    @Container(containerName = "DcLogins", partitionKeyPath = "/result/company",autoScale = true)
    public class DcLogins {
     private Result result;
 
    public class Result {
     private String company;

Just to mention, in the partitionKeyPath, the result is object of Result and company variable in should match the json object your dealing with {"company":"sapcustid","secret":"my secret"}

Related