San*_*v S 6 javascript stored-procedures azure-cosmosdb
我尝试使用 Azure 文档中的示例 sp 创建代码创建存储过程,但无法获取集合详细信息。它总是返回空值。
// SAMPLE STORED PROCEDURE
function sample(prefix) {
var collection = getContext().getCollection();
console.log(JSON.stringify(collection));
// 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.');
}
Run Code Online (Sandbox Code Playgroud)
结果显示没有找到文档,因为没有得到集合。我在执行时通过资源管理器传递了分区键。
您是否ToDoList使用Items集合创建了数据库?您可以通过 Azure 门户中的“快速入门”边栏选项卡执行此操作。
然后创建一个 SP 来针对该集合运行。不需要分区键,因此不需要额外的参数(留空)。
该集合是在没有任何文档的情况下创建的。您可以选择通过“查询资源管理器”边栏选项卡或通过“快速启动”边栏选项卡中提供的示例 ToDoList 应用程序添加文档。
| 归档时间: |
|
| 查看次数: |
1148 次 |
| 最近记录: |