如何从 cosmos db 中的现有 table 访问分区键
How to access partition key from an existing table in cosmos db
我正在尝试仅访问 cosmos db 中现有集合的分区键
我浏览了官方文档和 git 中心链接,但没有成功。请帮我。
注意:我能够通过使用 Document Client(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());
}
我正在尝试仅访问 cosmos db 中现有集合的分区键 我浏览了官方文档和 git 中心链接,但没有成功。请帮我。 注意:我能够通过使用 Document Client(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());
}