Omkar Subramaniam
Omkar Subramaniam

Reputation: 17

How to use the Partition Key in CosmosBD via SDK or via Select QUERY

Consider Below is my sample json.

    {         
      "servletname": "cofaxEmail",
      "servlet-class": "org.cofax.cds.EmailServlet",
      "init-param": {
      "mailHost": "mail1",
      "mailHostOverride": "mail2"    
    }

i have chosen "servletname" as my primary key as i will receive it in every request plus few 1000 server names are there it could be the best PK.

My Question is, to make the partition key work for me.

Do i have to specify the partition key option seperately like below

ItemResponse<ServerDto> ServerDtoResponse = await this.container.ReadItemAsync<ServerDto>(bocServerDto.mailHost, new PartitionKey(bocServerDto.servletname));

or

Including the partition key in the select query itself , without adding seperate new PartitionKey(), like

select * from r where r.servletname='cofaxEmail' and r.mailHost='mail1';

Crux of the question is: By passing partitionKey object in where condition of select query is it enough to utilize the partition key feature?

Thanks

Upvotes: 0

Views: 149

Answers (1)

Mark Brown
Mark Brown

Reputation: 8763

For any crud operation you would pass in the value for the partition key. For example, on a point read.

ItemResponse<ServerDto> ServerDtoResponse = await this.container.ReadItemAsync<ServerDto>(bocServerDto.mailHost, new PartitionKey("cofaxEmail"));

For a query, you can either pass it in the queryRequest options or use it in the query as the first filter predicate. Here is an example of using the queryRequest options.

thanks.

Upvotes: 1

Related Questions