【发布时间】: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