我是Azure DocumentDB的新手,在执行非常基本的存储过程时遇到了一些意外行为。存储过程(如下所示)返回“未找到文档”,但SELECT
语句正在查询的集合中填充了许多文档。令我感到困惑的是,在Query Explorer中运行相同的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.");
}
答案 0 :(得分:1)
sproc看起来很好。我在一个带有几个文档的集合上运行它,并且sproc按预期返回1个doc,所以我不能重复这个。以下是我的建议:
谢谢!