我是 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 个文档,所以我无法重现这个。这是我的建议:
- 尝试在小型集合上运行
- 更改存储过程,以便在 feed 为空且“未找到文档”的情况下,返回 options.continuation 并查看继续标记是否为空。查询可能被抢占,尽管这种情况不太可能发生。
谢谢!
关于Azure DocumentDB 存储过程不返回任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44291918/