gpt4 book ai didi

javascript - Azure cosmosDB 默认存储过程不起作用

转载 作者:行者123 更新时间:2023-12-02 23:39:01 24 4
gpt4 key购买 nike

当我创建存储过程时,这是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”,但它们都不起作用。

最佳答案

当你想执行存储过程时,你需要传递分区键的值。在您的情况下,您需要传递“1”或“2”作为分区键的值(而不是“id”),如下所示:

enter image description here

关于javascript - Azure cosmosDB 默认存储过程不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65591982/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com