当我创建存储过程时,这是 Azure 提供的默认示例代码。我的容器(学生)非常简单,只有 2 个项目。分区键是 id。
{name: "aaa", id: "1"}
{name: "bbb", id: "2"}
这是 Azure CosmosDB 提供的示例存储过程代码。
// SAMPLE STORED PROCEDURE
function sample(prefix) {
var collection = getContext().getCollection();
// Query documents and take 1st item.
var isAccepted = collection.queryDocuments(
collection.getSelfLink(),
'SELECT * FROM root r',
function (err, feed, options) {
if (err) throw err;
// Check the feed and if empty, set the body to 'no docs found',
// else take 1st element from feed
if (!feed || !feed.length) {
var response = getContext().getResponse();
response.setBody('no docs found');
}
else {
var response = getContext().getResponse();
var body = { prefix: prefix, feed: feed[0] };
response.setBody(JSON.stringify(body));
}
});
if (!isAccepted) throw new Error('The query was not accepted by the server.');
}
为什么它总是返回“找不到文档”?我尝试过不同的 sql 查询,例如“select * from Students”或“select * from root”或“select * from c”,但它们都不起作用。