如何从Cosmos DB中的现有表访问分区键 [英] How to access partition key from an existing table in cosmos db

查看:57
本文介绍了如何从Cosmos DB中的现有表访问分区键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试仅访问cosmos db中现有集合的分区键我已经通过官方doc和git hub链接,但是没有运气.请帮我.注意:通过使用Document Client(SQL api),我能够使用Java成功读取和写入数据

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)

推荐答案

请尝试以下代码:

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());
}

这篇关于如何从Cosmos DB中的现有表访问分区键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆