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?