Azure DocumentDB 存储过程不返回任何内容

标签 azure azure-cosmosdb nosql

我是 Azure DocumentDB 新手,在执行非常基本的存储过程时遇到一些意外行为。存储过程(如下所示)返回“未找到文档”,但 SELECT 语句查询的集合中填充了许多文档。更让我困惑的是,在查询资源管理器中运行相同的 SELECT 语句会导致按预期返回单个文档。我在这里错过了一些真正基本的东西吗?

function simple() {
    var collection = getContext().getCollection();

    // Query documents and take 1st item.
    var isAccepted = collection.queryDocuments(
        collection.getSelfLink(),
        'SELECT TOP 1 * FROM MyCollection c',
        function (err, feed, options) {
            if (err) throw err;

            // Check the feed and if it's empty, set the body to 'no docs found',
            // Otherwise just take 1st element from the feed.
            if (!feed || !feed.length) getContext().getResponse().setBody("no docs found");
            else getContext().getResponse().setBody(JSON.stringify(feed[0]));
        });

    if (!isAccepted) throw new Error("The query wasn't accepted by the server. Try again/use continuation token between API and script.");
}

最佳答案



存储过程看起来不错。我在一个包含几个文档的集合上运行了这个,存储过程按预期返回 1 个文档,所以我无法重现这个。这是我的建议:

  1. 尝试在小型集合上运行
  2. 更改存储过程,以便在 feed 为空且“未找到文档”的情况下,返回 options.continuation 并查看继续标记是否为空。查询可能被抢占,尽管这种情况不太可能发生。

谢谢!

关于Azure DocumentDB 存储过程不返回任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44291918/

相关文章:

azure - 嵌套 Java 对象/Json 的 CosmosDb 分区键 (Spring Boot)

mongodb - 关于 MongoDB 模式设计的建议

azure - documentdb 中的同构与异构

'tags-heavy' CRM 应用程序的 SQL 与 NoSQL 数据库

azure - 使用 PowerShell 中的 Get-AzMetric 从 Azure 经典云服务获取 "CpuPercentage"指标会返回错误

azure - ERROR_AZURE_DRIVE_DEV_PATH_NOT_SET 是什么意思?

c# - 尝试连接到azure数据库突然停止工作,抛出异常

c# - 如何从excel导入documentDB中的批量数据?

c# - 如何使用WindowsAzure.Storage.DataMovement?

azure - 如何在 Kusto 中使用 Materialize?