I am trying to write a procedure that logs that an Item was retrieved when the procedure is used. Right now, I can retrieve the items but I am just stuck on adding a single key and value to the item as I loop through the collection:
Here is my code:
function example(prefix) {
var collection = getContext().getCollection();
collection.chain().filter(function (doc) {
return doc.textStatus = "delivered";
}).map(function (doc) {
doc.note = "test";
var isAccepted = collection.replaceDocument(doc._self, doc, function (err) {
if (err) throw err;
});
if (!isAccepted) throw new Error("replaceDocument(metaItem) returned false.");
}).value();}
This is giving me this message:
Message: {"Errors":["Encountered exception while executing function. Exception = Error: {"Errors":["Requests originating from scripts cannot reference partition keys other than the one for which client request was submitted."]}
I have also tried setting the partition key of the doc (e.g. doc.partitionKey = "sid"), though I would assume it is set as the docs are being pulled from the collect.
Update
I thought that is code was sending docs to map function but when I checked again, it was not. I thought that my partition key was "/sid" or "sid" and entered those as strings for parameters of the stored procedure. This was after adding === and sid on filters. This produced no errors, but I could not log or change any docs.