使用分区键查询 cosmosdb
Query cosmosdb using partition key
我有一个部门作为 partitionKey 的员工 dto。
- 如何获取任意给定时间点的分区数?
- 如何使用 partitionKey 查询 cosmosdb(documentDB),查询资源管理器或 java api 都可以吗?
我尝试了什么:
List<Document> documentList = documentClient.queryDocuments(getCollection().getSelfLink(),"SELECT * FROM root r WHERE r.partitionKey ='" + partitionKey+"'", null).getQueryIterable().toList();
我最终从 java api 得到 IllegalStateException 状态异常并且查询导出器也没有给出任何输出。非常感谢任何帮助。
部分答案:
鉴于 Partition Key
属性的名称是 department
,请将您的查询更改为:
List<Document> documentList =
documentClient.queryDocuments(
getCollection().getSelfLink(),
"SELECT * FROM root r WHERE r.department ='" +
partitionKey + "'", null).getQueryIterable().toList();
您也可以通过将 link 提供给集合
来实现相同的目的
List<Document> documentList = documentClient.queryDocuments("/dbs/<yourdbname>/colls/<collectionname>","SELECT * FROM root r WHERE r.department ='" + partitionKey+"'", null).getQueryIterable().toList();
我有一个部门作为 partitionKey 的员工 dto。
- 如何获取任意给定时间点的分区数?
- 如何使用 partitionKey 查询 cosmosdb(documentDB),查询资源管理器或 java api 都可以吗?
我尝试了什么:
List<Document> documentList = documentClient.queryDocuments(getCollection().getSelfLink(),"SELECT * FROM root r WHERE r.partitionKey ='" + partitionKey+"'", null).getQueryIterable().toList();
我最终从 java api 得到 IllegalStateException 状态异常并且查询导出器也没有给出任何输出。非常感谢任何帮助。
部分答案:
鉴于 Partition Key
属性的名称是 department
,请将您的查询更改为:
List<Document> documentList =
documentClient.queryDocuments(
getCollection().getSelfLink(),
"SELECT * FROM root r WHERE r.department ='" +
partitionKey + "'", null).getQueryIterable().toList();
您也可以通过将 link 提供给集合
来实现相同的目的List<Document> documentList = documentClient.queryDocuments("/dbs/<yourdbname>/colls/<collectionname>","SELECT * FROM root r WHERE r.department ='" + partitionKey+"'", null).getQueryIterable().toList();