How to access partition key from an existing table in cosmos db

北城余情 提交于 2020-12-15 09:34:15

问题


I'm trying to access only partition key of an existing collection in cosmos db I have gone through official doc and git hub links but no luck. Please help me. Note: I'm able to successfully read and write data using java by using Document Client(SQL api)


回答1:


Please try this code:

DocumentClient dClient = new DocumentClient(endPoint,primary_key,null,null);
String collectionLink = String.format("/dbs/%s/colls/%s", databaseId, collectionId);
ResourceResponse<DocumentCollection> response = dClient.readCollection(collectionLink,new RequestOptions());
DocumentCollection documentCollection = response.getResource();
PartitionKeyDefinition partitionKeyDefinition = documentCollection.getPartitionKey();
Collection<String> paths = partitionKeyDefinition.getPaths();
if(paths.iterator().hasNext()){
    System.out.println(paths.iterator().next());
}


来源:https://stackoverflow.com/questions/63791156/how-to-access-partition-key-from-an-existing-table-in-cosmos-db

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!