存储过程azure Cosmos DB返回空集合 [英] Stored procedure azure Cosmos DB returns empty collection
问题描述
我尝试使用Azure文档中的示例sp创建代码创建存储过程,但我无法获取集合详细信息。它总是返回null。
I tried to create a stored procedure using the sample sp creation code from Azure docs, but i couldn't fetch the collection details. It always returns null.
// 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.');
}
控制台仅显示此信息。
The console shows only this.
结果显示没有找到文档,因为没有收集。我已经通过了分区键通过资源管理器执行。
the results shows no doc found because of not getting collection.I have passed the partition key at time of execution via explorer.
推荐答案
我有类似的问题。我认为当分区键不一个字符串时,Azure门户不会正确执行存储过程。
I had a similar issue. I think the Azure portal doesn't execute stored procedures properly when the partition key is not a string.
在我的情况下,我有一个partitionKey这是一个数字。当我通过门户网站执行存储过程时,我总是得到一个空的resultSet,即使我的数据库中有文档。当我稍微更改结构,并使我的partitionKey成为一个字符串时,存储过程工作正常。
In my case I had a partitionKey that is a number. When I executed the stored procedure via the portal I always got an empty resultSet, even though I had documents in my database. When I changed the structure a little, and made my partitionKey a string, the stored procedure worked fine.
这篇关于存储过程azure Cosmos DB返回空集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!