Java 如何从cosmos db中的现有表访问分区键

Java 如何从cosmos db中的现有表访问分区键,java,azure,azure-cosmosdb,azure-cosmosdb-sqlapi,Java,Azure,Azure Cosmosdb,Azure Cosmosdb Sqlapi,我试图只访问cosmos db中现有集合的分区键 我已经通过官方的doc和git中心链接,但没有运气。请帮帮我。 注意:通过使用文档客户端(SQL api),我能够使用java成功地读写数据。请尝试以下代码: DocumentClient dClient = new DocumentClient(endPoint,primary_key,null,null); String collectionLink = String.format("/dbs/%s/colls/%s",

我试图只访问cosmos db中现有集合的分区键 我已经通过官方的doc和git中心链接,但没有运气。请帮帮我。 注意:通过使用文档客户端(SQL api),我能够使用java成功地读写数据。

请尝试以下代码:

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());
}
DocumentClient dClient=newdocumentclient(端点,主键,null,null);
String collectionLink=String.format(“/dbs/%s/colls/%s”,databaseId,collectionId);
ResourceResponse=dClient.readCollection(collectionLink,new RequestOptions());
DocumentCollection DocumentCollection=response.getResource();
PartitionKeyDefinition PartitionKeyDefinition=documentCollection.getPartitionKey();
集合路径=partitionKeyDefinition.getPaths();
if(path.iterator().hasNext()){
System.out.println(path.iterator().next());
}

是表API还是SQL API?在标题中你们提到了表,但在描述中你们提到了SQLAPI。两者都不同。编辑我的问题。我正在使用SQL apiCheck,如果这是您想要的,您想要获取集合的分区密钥吗?是的,Steve,我想要获取分区密钥