我正在使用Azure Cosmos DB SQL API。我编写的存储过程将获取数据并保持响应API提要。
无法执行存储过程testProcedure进行收集 iotcollection: {“ code”:400,“ body”:“ {\” code \“:\” BadRequest \“,\” message \“:\”消息: {\\“错误\\”:[\\“执行功能时遇到异常。 异常=错误:内存不足\\ r \\ n堆栈跟踪: undefined \\“]} \ r \ nActivityId:c286cbb6-34c1-4929-a148-915544b20ce6, 请求URI: / apps / 59d3b9ef-17ca-4bbf-8a11-39d0199a8d29 / services / 1b26e00f-1f51-4d34-88ec-4090b8e7db00 / partitions / 45a313b7-2cf2-419e-9885-48bf9cfe6277 / replicas / 131862936473830809p /, RequestStats:\ r \ nRequestStartTime:2018-11-10T05:46:36.4852333Z, 尝试的区域数:1 \ r \ n,SDK: Microsoft.Azure.Documents.Common / 2.1.0.0 \“}”,“ activityId”:“ c286cbb6-34c1-4929-a148-915544b20ce6”}
我的存储过程非常简单,我只想看看在给定的时间我可以从cosmos DB中获取多少记录并作为响应发送。
// SAMPLE STORED PROCEDURE
function sample(prefix) {
var collection = getContext().getCollection();
// Query documents and take 1st item.
var isAccepted = collection.queryDocuments(
collection.getSelfLink(),
'SELECT r.data 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] };
var str = 'str';
for ( var i =0 ; i < 100 ; i = i +1 ){
str = str + str ;
body .str = feed[0];
}
response.setBody(JSON.stringify(body));
}
});
if (!isAccepted) throw new Error('The query was not accepted by the server.');
}
答案 0 :(得分:0)
我确定Out-Of-Memory
错误的原因是str
字符串在循环期间过长。看来str
字符串对您的测试没有用,它没有添加到响应中。
请删除它,示例存储过程将正常运行。