【问题标题】:Azure DocumentDB stored procedure returns nothingAzure DocumentDB 存储过程不返回任何内容
【发布时间】:2017-05-31 18:10:25
【问题描述】:

我是 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.");
}

【问题讨论】:

  • 只是好奇:你有分区集合还是单分区集合?
  • 是的,集合是分区的。
  • 有同样的问题。 SP 应该没问题,返回 0 个文档。分区集合。

标签: azure azure-cosmosdb nosql


【解决方案1】:



存储过程看起来不错。我在带有几个文档的集合上运行了这个,并且存储过程按预期返回了 1 个文档,所以我无法重现这个。以下是我的推荐:

  1. 尝试在小集合上运行
  2. 更改存储过程,以便在提要为空的情况下,连同“未找到文档”一起返回 options.continuation 并查看继续令牌是否为空。可能是查询被抢占了,尽管这不太可能。

谢谢!

【讨论】:

    猜你喜欢
    • 2011-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多