Create a document in Stored Procedure raises a Partition Key error

Fred 1 Reputation point
2021-04-14T05:32:52.433+00:00

Requests originating from scripts cannot reference partition keys other than the one for which client request was submitted

I'm simply trying to create a document from a stored procedure, here is the sample code:

function sample(prefix) {
    var collection = getContext().getCollection();

    var isAccepted = collection.createDocument(
        collection.getSelfLink(),
        {tests_stored_proc: Date.now()},
        {disableAutomaticIdGeneration: false},
    function (err, item, options) {
        if (err) throw err;

        var response = getContext().getResponse();
        var body = { prefix: prefix, item: item };
        response.setBody(JSON.stringify(body));
    });

    if (!isAccepted) throw new Error('The query was not accepted by the server.');
}

I create this stored procedure from Azure Dashboard, and attempted to execute it from there as well. The container was created a long time ago at which point I don't believe partition keys had to be defined. I'm not sure which value I should provide as "Partition key" when I execute the procedure, but none of the ones I've tried have worked.

Beside creating documents, I was hoping to test whether throwing an error would cancel the creation of the documents created within the transaction. I also want to validate whether created documents can be queried within the transaction.

Thank you.

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,442 questions
{count} votes