我正在使用 Azure Cosmos DB SQL API。我已经编写了存储过程将获取数据并保留在响应 API 提要中。
无法执行集合 iotcollection 的存储过程 testProcedure: {"code":400,"body":"{\"code\":\"BadRequest\",\"message\":\"Message: {\\"Errors \\":[\\"执行函数时遇到异常。Exception = Error: Out of memory\\r\\nStack trace: undefined\\"]}\r\nActivityId: c286cbb6-34c1-4929-a148-915544b20ce6, Request 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.');
}