3

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.

0

2 Answers 2

7

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();
Sign up to request clarification or add additional context in comments.

3 Comments

thanks much @gaurav, is there a way to get number of partition at any given point of time?
Please see this: stackoverflow.com/questions/43319308/…. Let me know if it helps and I will include it in the answer.
I hope partitionKey is not a user controllable input because this is vulnerable to SQLi if it comes from the user
1

You can also achieve the same thing by providing the link to collection

List<Document> documentList = documentClient.queryDocuments("/dbs/<yourdbname>/colls/<collectionname>","SELECT * FROM root r WHERE r.department ='" + partitionKey+"'", null).getQueryIterable().toList();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.