A simple stored procedure using readDocument
function in CosmosDB/DocumentDB, but it does not work.
function testRead() {
var collection = getContext().getCollection();
var docId = collection.getSelfLink() + 'docs/myDocId';
// Query documents and take 1st item.
var isAccepted = collection.readDocument(docId, {}, function (err, doc, options) {
if (err) throw err;
response.setBody(JSON.stringify(doc));
});
if (!isAccepted) throw new Error('The query was not accepted by the server.');
}
it always get error code 400.
{"code":400,"body":"{\"code\":\"BadRequest\",\"message\":\"Message: {\\"Errors\\":[\\"Encountered exception while executing Javascript. Exception = Error: Error creating request message\\r\\nStack trace: Error: Error creating request message\\n at readDocument (testRead.js:512:17)\\n at testRead (testRead.js:8:5)\\n at __docDbMain (testRead.js:18:5)\\n at Global code (testRead.js:1:2)\\"]}\r\nActivityId: 2fb0f7ef-c192-4b56-b8bb-9681c9f8fa6e, Request URI: /apps/DocDbApp/services/DocDbServer22/partitions/a4cb4962-38c8-11e6-8106-8cdcd42c33be/replicas/1p/, RequestStats: , SDK: Microsoft.Azure.Documents.Common/1.22.0.0\"}","activityId":"2fb0f7ef-c192-4b56-b8bb-9681c9f8fa6e","substatus":400}
Anyone can help me ?