Stored Procedure not updating some documents in Cosmos DB if a single Partition key have many documents

Santo George Daniel 0 Reputation points
2023-12-08T15:15:11.07+00:00

I have a stored procedure to replace some special characters and it is working fine for documents.

I have come across an issue, that If I have a partition key with many documents(200), then this stored procedure is executing only first few documents and then skipping other docs for that partition key.

Plaese advise whether anyone encounter the same issue

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
{count} votes

1 answer

Sort by: Most helpful
  1. Sajeetharan 2,261 Reputation points Microsoft Employee
    2023-12-13T04:17:08.9866667+00:00

    Looks like you're using the query within stored procedure which migh span across multiple pages, you need to use the continuation token in that case. You can look at this example below,

     function tryQueryAndDelete(continuation) {     var requestOptions = { continuation: continuation };     var isAccepted = container.queryDocuments(       containerLink,       query,       requestOptions,       function(err, retrievedDocs, responseOptions) {         if (err) throw err;         if (retrievedDocs.length > 0) {           tryDelete(retrievedDocs);         } else if (responseOptions.continuation) {           tryQueryAndDelete(responseOptions.continuation);         } else {           responseBody.continuation = false;           response.setBody(responseBody);         }       }     );     if (!isAccepted) {       response.setBody(responseBody);     }   }
    

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.