2

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"}

Alferd Nobel
  • 3,185
  • 2
  • 30
  • 35
  • You can have nested path configured – Sajeetharan Aug 31 '21 at 07:50
  • could you please elaborate on your that ? code snippets will be of help – Alferd Nobel Aug 31 '21 at 15:15
  • It is not possible to specify an object as your partition key in Cosmos DB. There is work however to provide sub-partitioning for the Core (SQL) API that allows you to specify up to 3 properties that act as a hierarchy for your partitions. If you are interested, there is a private preview of this. Sign up is here. https://aka.ms/cosmos-subpartitioning-signup – Mark Brown Sep 02 '21 at 15:10
  • @MarkBrown, thanks ! here's how I solved it for now (my ans. below) . – Alferd Nobel Sep 03 '21 at 00:56

1 Answers1

0

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"}

Alferd Nobel
  • 3,185
  • 2
  • 30
  • 35