Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query cosmosdb using partition key

I have an employee dto with department as partitionKey.

  1. How to get number of partition at any given of point of time?
  2. How to query cosmosdb(documentDB) using partitionKey, either query explorer or java api will do?

What I tried:

List<Document> documentList = documentClient.queryDocuments(getCollection().getSelfLink(),"SELECT * FROM root r WHERE r.partitionKey ='" + partitionKey+"'", null).getQueryIterable().toList();

I end up getting IllegalStateException state exception from java api and query exporter also did't give any output. Any help is highly appreciable.

like image 657
lambodar Avatar asked Nov 29 '25 11:11

lambodar


1 Answers

Partial answer:

Given the name of Partition Key attribute is department, please change your query to:

List<Document> documentList = 
    documentClient.queryDocuments(
         getCollection().getSelfLink(),
              "SELECT * FROM root r WHERE r.department ='" + 
              partitionKey + "'", null).getQueryIterable().toList();
like image 112
Gaurav Mantri Avatar answered Dec 01 '25 01:12

Gaurav Mantri



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!