Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用分区键查询SDB_Java_Azure_Azure Cosmosdb - Fatal编程技术网

Java 使用分区键查询SDB

Java 使用分区键查询SDB,java,azure,azure-cosmosdb,Java,Azure,Azure Cosmosdb,我有一个部门为partitionKey的员工dto 如何获得任意给定时间点的分区数 如何使用partitionKey查询cosmosdb(documentDB),查询资源管理器或java api都可以 我尝试的是: List<Document> documentList = documentClient.queryDocuments(getCollection().getSelfLink(),"SELECT * FROM root r WHERE r.partitionKey ='"

我有一个部门为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();
    
    List documentList=documentClient.queryDocuments(getCollection().getSelfLink(),“从根r中选择*,其中r.partitionKey='“+partitionKey+”,null)。getQueryIterable().toList();
    
    我最终从JavaAPI获得了IllegalStateException状态异常,而查询导出器也没有给出任何输出。任何帮助都是值得赞赏的。

    部分回答:

    鉴于
    分区键
    属性的名称为
    部门
    ,请将查询更改为:

    List<Document> documentList = 
        documentClient.queryDocuments(
             getCollection().getSelfLink(),
                  "SELECT * FROM root r WHERE r.department ='" + 
                  partitionKey + "'", null).getQueryIterable().toList();
    
    列表文档列表=
    documentClient.queryDocuments(
    getCollection().getSelfLink(),
    “从根r中选择*,其中r.department=”+
    partitionKey+“'”,null);
    
    您也可以通过提供到集合的链接来实现同样的目的

    List<Document> documentList = documentClient.queryDocuments("/dbs/<yourdbname>/colls/<collectionname>","SELECT * FROM root r WHERE r.department ='" + partitionKey+"'", null).getQueryIterable().toList();
    
    List documentList=documentClient.queryDocuments(“/dbs//colls/”,“从根r中选择*,其中r.department=”+partitionKey+”,null)。GetQueryInterable().toList();
    
    非常感谢@gaurav,有没有办法在任何给定的时间点获取分区数?请参见以下内容:。让我知道它是否有帮助,我会将其包括在答案中。我希望
    partitionKey
    不是用户可以控制的输入,因为如果它来自用户,则容易受到
    SQLi
    的攻击