Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.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
Azure cosmosdb Cosmos DB存储过程未返回任何结果_Azure Cosmosdb - Fatal编程技术网

Azure cosmosdb Cosmos DB存储过程未返回任何结果

Azure cosmosdb Cosmos DB存储过程未返回任何结果,azure-cosmosdb,Azure Cosmosdb,我一直在阅读有限的文档,从我所看到的来看,这个查询应该可以工作 // SAMPLE STORED PROCEDURE function sample() { var prefix = ""; var collection = getContext().getCollection(); var data = collection.readDocuments(collection.getSelfLink()); console.log(data); console.log(JSO

我一直在阅读有限的文档,从我所看到的来看,这个查询应该可以工作

// SAMPLE STORED PROCEDURE
function sample() {
var prefix = "";
var collection = getContext().getCollection();
var data = collection.readDocuments(collection.getSelfLink());
console.log(data);
console.log(JSON.stringify(data));
// Query documents and take 1st item.
var isAccepted = collection.queryDocuments(
    collection.getSelfLink(),
    'SELECT * FROM root r',
function (err, feed, options) {
    if (err) throw err;

    // Check the feed and if empty, set the body to 'no docs found', 
    // else take 1st element from feed
    if (!feed || !feed.length) {
        var response = getContext().getResponse();
        response.setBody('no docs found');
    }
    else {
        var response = getContext().getResponse();
        var body = { prefix: prefix, feed: feed[0] };
        response.setBody(JSON.stringify(body));
    }
});

if (!isAccepted) throw new Error('The query was not accepted by the server.');
}
毕竟,这只是门户生成的示例查询。唯一的问题是它不会返回任何结果

  • 藏品有7000份文件
  • 它由一个prop type
    /EmailTypeId
  • 执行查询时,我提交的分区值为
    5
    (这是所有当前记录的分区值)
  • 我正在console.logging调用
    collection.readDocuments
    ,它应该返回所有文档,但只返回值
    true
我正在尝试返回所有记录,以便按id和计数进行聚合。如何让这个查询实际返回数据? 以下是集合中一个文档架构的示例屏幕截图
这是提供分区值的输入表单

更新
我创建了一个新集合作为控件。此集合没有分区键,似乎相同的查询返回该集合中的结果。因此,问题必须出现在我提供的第二个屏幕截图中。可能我提供的分区键不正确。

我认为您需要限制响应大小,因为cosmo有一个限制。我在我的存储过程中添加了类似的内容来缓解这种情况:

if (responseSize + queryPageSize < 1024 * 1024) {
      // Append query results to nodesBatch.
      nodesBatch = nodesBatch.concat(documentsRead);

      // Keep track of the response size.
      responseSize += queryPageSize;

      if (responseOptions.continuation) {
        // If there is a continuation token... Run the query again to get the next page of results
        lastContinuationToken = responseOptions.continuation;
        getNodes(responseOptions.continuation);
      } else {
        // If there is no continutation token, we are done. Return the response.
        response.setBody({
          "message": "Query completed succesfully.",
          "queryResponse": nodesBatch
        });
      }
    } else {
      // If the response size limit reached; run the script again with the lastContinuationToken as a script parameter.
      response.setBody({
        "message": "Response size limit reached.",
        "lastContinuationToken": lastContinuationToken,
        "queryResponse": nodesBatch
      });
    }
  });
if(responseSize+queryPageSize<1024*1024){
//将查询结果追加到NodeBatch。
nodesBatch=nodesBatch.concat(documentsRead);
//跟踪响应大小。
responseSize+=查询页面大小;
if(responseOptions.continuation){
//如果有延续标记…请再次运行查询以获取下一页的结果
lastContinuationToken=responseOptions.continuation;
getNodes(responseOptions.continuation);
}否则{
//如果没有Continuation令牌,则完成。返回响应。
回应({
“消息”:“查询已成功完成”,
“queryResponse”:nodesBatch
});
}
}否则{
//如果达到响应大小限制,请使用lastContinuationToken作为脚本参数再次运行脚本。
回应({
“消息”:“已达到响应大小限制。”,
“lastContinuationToken”:lastContinuationToken,
“queryResponse”:nodesBatch
});
}
});
让我知道这对你是如何起作用的


此外,请检查您的集合名称,并使用该名称而不是
root

,只需在azure文档上阅读,门户中的输入参数将作为字符串发送。这可能就是问题所在。可能输入的分区键值也是作为字符串发送的,但我的分区键值是int。很抱歉,您的答案不完整。我读了大约10遍,仍然不明白我应该做什么:)我只知道有一些限制,我应该处理它,但如何-这是一个大问号。我感觉到你的痛苦。。。不应该这么难。