如何获取Cosmos DB存储过程请求的正文?

问题描述 投票:0回答:1

从Postman查询我的Cosmos DB存储过程时出现以下错误,我不明白为什么:

{
   "code": "BadRequest",
   "message": "Message: {\"Errors\":[\"Encountered exception while executing Javascript. Exception = TypeError: Object doesn't support property or method 'getBody'\\r\\nStack trace: TypeError: Object doesn't support property or method 'getBody'\\n   at storedProcedure (Test.js:7:9)\\n   at __docDbMain (Test.js:13:5)\\n   at Global code (Test.js:1:2)\"]}\r\nActivityId: f01827c0-4992-4560-bec1-e015b5678cf8, Request URI: /apps/ce1979d6-d776-4e39-bc44-85912cdd1c9f/services/95b9183f-4865-4ddb-933b-1869cb325207/partitions/b7168d10-e69f-4dae-87d8-91a07e5d6cfd/replicas/131638498361729976p/, RequestStats: , SDK: Microsoft.Azure.Documents.Common/1.20.0.0"
}

我创建的SP非常简单:

function storedProcedure(){

        var context = getContext();
        var response = context.getResponse();

        var item = context.getRequest().getBody();

        response.setBody(item);
}

似乎getRequest方法无法找到请求,因为其他请求方法(在这里找到http://azure.github.io/azure-documentdb-js-server/)也失败了。

azure-cosmosdb server-side-scripting
1个回答
1
投票

正文可用作存储过程的参数。例如,如果将定义更改为以下内容,则可以获得以下情况:

function storedProcedure(body){
    var context = getContext();
    var response = context.getResponse();
    response.setBody(body);
}
© www.soinside.com 2019 - 2024. All rights reserved.