Azure cosmos db 存储过程不起作用
Azure cosmos db stored procedure not work
我在 MSDN 上查找如何在 CosmoDB 中编写存储过程。
我找到以下简单示例:
var helloWorldStoredProc = {
id: "helloWorld",
serverScript: function () {
var context = getContext();
var response = context.getResponse();
response.setBody("Hello, World");
}
}
但是如果我尝试在 cosmos db 中执行它,我会收到以下错误消息:
Failed to execute stored procedure helloWorldId for container Measure: {"code":400,"body":{"code":"BadRequest","message":"Message: {\"Errors\":[\"Encountered exception while compiling Javascript. Exception = SyntaxError: Syntax error\r\nSource information: line: 1, column: 36, source line:\r\n(function __docDbMain() { var fn = var helloWorldStoredProc = {\"]}\r\nActivityId: 21c41459-2e6b-407b-af9b-80c81ef54746, Request URI: /apps/a6f25760-7394-4bfb-bafc-7ea08f3f3f13/services/6574355c-d55b-43fa-b388-b270ebbd4403/partitions/409dd415-cb4d-49f0-9d16-11c07c880ee2/replicas/132070570012201722p/, RequestStats: \r\nRequestStartTime: 2019-07-08T12:28:32.6776283Z, RequestEndTime: 2019-07-08T12:28:32.7176085Z, Number of regions attempted: 1\r\nResponseTime: 2019-07-08T12:28:32.7176085Z, StoreResult: StorePhysicalAddress: rntbd://cdb-ms-prod-australiaeast1-fd3.documents.azure.com:14032/apps/a6f25760-7394-4bfb-bafc-7ea08f3f3f13/services/6574355c-d55b-43fa-b388-b270ebbd4403/partitions/409dd415-cb4d-49f0-9d16-11c07c880ee2/replicas/132070570012201722p/, LSN: 7, GlobalCommittedLsn: 7, PartitionKeyRangeId: 0, IsValid: True, StatusCode: 400, SubStatusCode: 65535, RequestCharge: 1.7, ItemLSN: -1, SessionToken: -1#7, UsingLocalLSN: False, TransportException: null, ResourceType: StoredProcedure, OperationType: ExecuteJavaScript\r\n, SDK: Microsoft.Azure.Documents.Common/2.4.0.0"},"headers":{"access-control-allow-credentials":"true","access-control-allow-origin":"https://cosmos.azure.com","content-type":"application/json","lsn":"7","strict-transport-security":"max-age=31536000","x-ms-activity-id":"21c41459-2e6b-407b-af9b-80c81ef54746","x-ms-cosmos-llsn":"7","x-ms-cosmos-quorum-acked-llsn":"7","x-ms-current-replica-set-size":"4","x-ms-current-write-quorum":"3","x-ms-gatewayversion":"version=2.4.0.0","x-ms-global-committed-lsn":"7","x-ms-last-state-change-utc":"Mon, 08 Jul 2019 10:56:52.631 GMT","x-ms-number-of-read-regions":"0","x-ms-quorum-acked-lsn":"7","x-ms-request-charge":"1.7","x-ms-schemaversion":"1.8","x-ms-serviceversion":"version=2.4.0.0","x-ms-session-token":"0:-1#7","x-ms-substatus":"65535","x-ms-transport-request-id":"1","x-ms-xp-role":"1","x-ms-throttle-retry-count":0,"x-ms-throttle-retry-wait-time-ms":0},"activityId":"21c41459-2e6b-407b-af9b-80c81ef54746","substatus":65535}
谁能帮帮我?
提前致谢,
西蒙
此格式不是有效的 Cosmos DB 存储过程格式。
它应该是这样的:
function helloWorldStoredProc() {
var context = getContext();
var response = context.getResponse();
response.setBody("Hello, World");
}
下面是执行的示例代码:
我在 MSDN 上查找如何在 CosmoDB 中编写存储过程。
我找到以下简单示例:
var helloWorldStoredProc = {
id: "helloWorld",
serverScript: function () {
var context = getContext();
var response = context.getResponse();
response.setBody("Hello, World");
}
}
但是如果我尝试在 cosmos db 中执行它,我会收到以下错误消息:
Failed to execute stored procedure helloWorldId for container Measure: {"code":400,"body":{"code":"BadRequest","message":"Message: {\"Errors\":[\"Encountered exception while compiling Javascript. Exception = SyntaxError: Syntax error\r\nSource information: line: 1, column: 36, source line:\r\n(function __docDbMain() { var fn = var helloWorldStoredProc = {\"]}\r\nActivityId: 21c41459-2e6b-407b-af9b-80c81ef54746, Request URI: /apps/a6f25760-7394-4bfb-bafc-7ea08f3f3f13/services/6574355c-d55b-43fa-b388-b270ebbd4403/partitions/409dd415-cb4d-49f0-9d16-11c07c880ee2/replicas/132070570012201722p/, RequestStats: \r\nRequestStartTime: 2019-07-08T12:28:32.6776283Z, RequestEndTime: 2019-07-08T12:28:32.7176085Z, Number of regions attempted: 1\r\nResponseTime: 2019-07-08T12:28:32.7176085Z, StoreResult: StorePhysicalAddress: rntbd://cdb-ms-prod-australiaeast1-fd3.documents.azure.com:14032/apps/a6f25760-7394-4bfb-bafc-7ea08f3f3f13/services/6574355c-d55b-43fa-b388-b270ebbd4403/partitions/409dd415-cb4d-49f0-9d16-11c07c880ee2/replicas/132070570012201722p/, LSN: 7, GlobalCommittedLsn: 7, PartitionKeyRangeId: 0, IsValid: True, StatusCode: 400, SubStatusCode: 65535, RequestCharge: 1.7, ItemLSN: -1, SessionToken: -1#7, UsingLocalLSN: False, TransportException: null, ResourceType: StoredProcedure, OperationType: ExecuteJavaScript\r\n, SDK: Microsoft.Azure.Documents.Common/2.4.0.0"},"headers":{"access-control-allow-credentials":"true","access-control-allow-origin":"https://cosmos.azure.com","content-type":"application/json","lsn":"7","strict-transport-security":"max-age=31536000","x-ms-activity-id":"21c41459-2e6b-407b-af9b-80c81ef54746","x-ms-cosmos-llsn":"7","x-ms-cosmos-quorum-acked-llsn":"7","x-ms-current-replica-set-size":"4","x-ms-current-write-quorum":"3","x-ms-gatewayversion":"version=2.4.0.0","x-ms-global-committed-lsn":"7","x-ms-last-state-change-utc":"Mon, 08 Jul 2019 10:56:52.631 GMT","x-ms-number-of-read-regions":"0","x-ms-quorum-acked-lsn":"7","x-ms-request-charge":"1.7","x-ms-schemaversion":"1.8","x-ms-serviceversion":"version=2.4.0.0","x-ms-session-token":"0:-1#7","x-ms-substatus":"65535","x-ms-transport-request-id":"1","x-ms-xp-role":"1","x-ms-throttle-retry-count":0,"x-ms-throttle-retry-wait-time-ms":0},"activityId":"21c41459-2e6b-407b-af9b-80c81ef54746","substatus":65535}
谁能帮帮我? 提前致谢, 西蒙
此格式不是有效的 Cosmos DB 存储过程格式。
它应该是这样的:
function helloWorldStoredProc() {
var context = getContext();
var response = context.getResponse();
response.setBody("Hello, World");
}
下面是执行的示例代码: