Reputation: 759
I am trying to set the property of all documents of a particular user to false. I am using Stored Procedure to do the same. The Below Procedure fetches only a partial of the records and updates them.
I have a total of 2399 documents. But the Procedure fetches only 1332 and updates them.
function spBulkUpdateTrackInventory(tenantId) {
var queryDocument = " select * from c where c.tenantId = '" + tenantId + "'";
var collection = getContext().getCollection();
var collectionLink = collection.getSelfLink();
var response = getContext().getResponse();
var responseBody = {
updatedCount: 0,
continuation: true
};
fetchProducts();
function fetchProducts(continuation) {
var requestOptions = { continuation: continuation, pageSize:-1};
var isAccepted = collection.queryDocuments(collection.getSelfLink(), queryDocument, requestOptions,
function (err, retrievedDocs, responseOptions) {
if (err) throw new Error("Error" + err.message);
if (retrievedDocs.length > 0)
{
updateTrackInventory(retrievedDocs, responseOptions.continuation);
}
});
if (!isAccepted) getContext().getResponse().setBody(responseBody);
}
function updateTrackInventory(documents, continuation) {
for (var cnt = 0; cnt < documents.length; cnt++)
{
newdocument = documents[cnt];
newdocument.trackInventory = true;
responseBody.updatedCount++;
var isAccepted = collection.replaceDocument(documents[cnt]._self, newdocument);
if (!isAccepted) {
response.setBody(responseBody);
}
}
if (continuation) {
fetchProducts(continuation);
}
responseBody.continuation = false;
response.setBody(responseBody);
}
}
What am I missing?
Upvotes: 0
Views: 1171
Reputation: 1
It is possible that Resource Units (RU) limit at either the Cosmos DB resource level and/or the container level is limiting the number of documents that the stored proc can query and update a single execution. Try bumping up the number at both these levels (subject to additional charges) and retesting the stored proc.
Upvotes: 0
Reputation: 23782
I created 3000
documents which are half-partitioned by name
partition key to test your code.It works fine.
I suggest you checking if the SQL result is consistent running in stored procedure and in query shell.In addition, you could follow this case How to debug Azure Cosmos DB Stored Procedures? : to use console.log
to debug your stored procedure.
Hope it helps you.
Upvotes: 1