DocumentDB: Unable to update ALL records - Only 100 records are updated at a time
<p>In my document, when few fields(post,price,desc) i want to turn off the approval flag.</p>

<p>For this problem, I am first turning off the flag for all the records in the document and then turning on the flag for only unique records.</p>

<pre><code>function SProc() {
    var collection = getContext().getCollection();
    var collectionLink = collection.getSelfLink();
    var response = getContext().getResponse();
    var counter = 0;
    var responseBody = {
        updated: 0,
        continuation: true,
        error: "",
        log: ""
    };

    // Validate input.
    getFullListOfPosts();

    // Recursively queries for a document by id w/ support for continuation tokens.
    // Calls findDuplicates(document) as soon as the query returns a document.
    function getFullListOfPosts(continuation) {
        var query = {
            query: "select * from root r ORDER BY r.created.epoch DESC"
        };

        var requestOptions = {
            continuation: continuation
        };

        var isAccepted = collection.queryDocuments(collectionLink, query, requestOptions, proccessFullListOfPosts);

        // If we hit execution bounds - throw an exception.
        if (!isAccepted) {
            responseBody.log += "Query not accepted";
            response.setBody(responseBody);
            throw new Error("The stored procedure timed out");
        }
    }

    function proccessFullListOfPosts(err, documents, responseOptions) {
        if (err) {
            responseBody.error = err;
            throw err;
        }
        if (documents.length &gt; 0) {
            responseBody.log += "Total records: " + documents.length;
            var filtered = documents.filter(function(a) {
                var key = a.posted_by + '|' + a.price + '|' + a.description + '|' + a.compare_price;
                if (!this[key]) {
                    this[key] = true;
                    return true;
                }
            }, Object.create(null))
            for (var i = 0; i &lt; documents.length; i++) {
                var allRec = documents[i]
                disableAllrecords(allRec);
            }
            for (var i = 0; i &lt; filtered.length; i++) {
                var uniqRec = filtered[i]
                enableUniqueRecords(uniqRec);
            }
        }
        if (responseOptions.continuation) {
            // Else if the query came back empty, but with a continuation token;
            // repeat the query w/ the token.
            getFullListOfPosts(responseOptions.continuation);
        }
    }

    function disableAllrecords(element) {
        element.is_approved = false;
        element.likes = 56;
        responseBody.log += " Will disable " + element.id + element.is_approved + element.likes;
        var requestOptions = {
            etag: element._etag
        };
        var isAccepted = collection.replaceDocument(element._self, element, requestOptions, function(err, updatedDocument, responseOptions) {
            if (err) throw err; 
            counter++;
            responseBody.log += " Disabled: " + element.id + " with approval:" + element.is_approved + " Likes:" + element.likes; 
        });
        if (!isAccepted) {
            throw new Error("The stored procedure timed out while disabling");
        }
    }

    function enableUniqueRecords(x) {
        x.is_approved = true;
        x.likes = 65;
        responseBody.log += " Will enable " + x.id + x.is_approved + x.likes;
        var requestOptions = {
            etag: x._etag
        };
        var isAccepted = collection.replaceDocument(x._self, x, requestOptions, function(err, updatedDocument, responseOptions) {
            if (err) throw err; 
            counter++;
            responseBody.log += " Enabled: " + x.id + " with approval:" + x.is_approved + " Likes:" + x.likes; 
        });
        if (!isAccepted) {
            throw new Error("The stored procedure timed out while enabling");
        }
    }
}
</code></pre>

<p>I am getting an error in enableUniqueRecords(). I am not able to understand what and why I am getting an error. </p>

<p>It says: </p>

<blockquote>
  <p>Error: {"Errors":["One of the specified pre-condition is not met"]}</p>
</blockquote>