为什么 Document DB 过程 returns 在 querydocument 上只有 100 个文档?

Why Document DB procedure returns only 100 docs on querydocument?

我在文档数据库中有以下过程。它在 DocumentDb 脚本资源管理器中执行良好,但结果 returns 是部分的。我有超过 250 个文档满足我在查询资源管理器中检查的给定 where 子句。但是当我 运行 来自脚本资源管理器的过程计数(在过程中定义)总是 100。

下面是我的程序 -

function getInvoice(pageNo, numberOfRecords, member, searchText, customerGroupId,ResellerId) {
var collectionReseller = getContext().getCollection();
var filterquery ;
var count=0, invoiceAmountTotal=0, referalCommissionTotal=0, developerCommissionTotal=0;
var customerIdString='';
var InvoiceList = [];
var whereClause;
if (customerGroupId != "") {
filterquery = 'SELECT c.id from c where c.Type="Customer" and c.CustomerGroupID="' + customerGroupId + '"';
var isAccepted = collectionReseller.queryDocuments(
    collectionReseller.getSelfLink(), filterquery,
    function (err, documents, responseOptions) {
        var docCount = documents.length;
        documents.forEach(function (doc) {
            docCount--;
            if (docCount > 0)
                customerIdString = customerIdString + '"' + doc.id + '", '
            else
                customerIdString = customerIdString + '"' + doc.id + '" '
        })
        whereClause = 'where  r.Type="Invoice" and r.CustomerID IN (' + customerIdString + ')'

        var filterquery1 = 'SELECT * FROM root r  ';
        if (member.length > 0) {

            member.forEach(function (val, i) {
                whereClause = whereClause + ' and contains(r.' + member[i] + ',"' + searchText[i] + '")';
            });
        }
        isAccepted = collectionReseller.queryDocuments(
         collectionReseller.getSelfLink(), filterquery1 + whereClause,
         function (err, invoiceDoc) {
             var qr = filterquery1 + whereClause;
        count = invoiceDoc.length;
             invoiceDoc.forEach(function (doc) {
                 invoiceAmountTotal = parseFloat(invoiceAmountTotal) + parseFloat(doc.InvoiceAmount);
                 referalCommissionTotal = parseFloat(referalCommissionTotal) + parseFloat(doc.ReferralCommission);
                 developerCommissionTotal= parseFloat(developerCommissionTotal) + parseFloat(doc.DeveloperCommission);
                 InvoiceList.push(doc);
             });


             InvoiceList.sort(SortByID);
             InvoiceList = InvoiceList.slice(pageNo * numberOfRecords, pageNo * numberOfRecords + numberOfRecords);
             // Check the feed and if empty, set the body to 'no docs found', 
             // else take 1st element from feed
             getContext().getResponse().setBody(JSON.stringify({ InvoiceList, count, invoiceAmountTotal, referalCommissionTotal, developerCommissionTotal }));

         });
    });
}
else
{   
    whereClause = ' where r.Type = "Invoice" and r.ResellerID = "'+ ResellerId + '"';

    filterquery = 'SELECT * FROM root r ';
    if(member.length > 0) {
    member.forEach(function (val, i) {
        whereClause = whereClause + ' and contains(r.' + member[i] + ',"' + searchText[i] + '")';
    });
}


 filterquery = filterquery + whereClause;

 var isAccepted = collectionReseller.queryDocuments(
    collectionReseller.getSelfLink(), filterquery,
    function (err, documents, responseOptions) {
        if (err) throw err;
        invoiceDoc = documents;
count =invoiceDoc.length;
            invoiceDoc.forEach(function (doc) {
                InvoiceList.push(doc);
                invoiceAmountTotal = parseFloat(invoiceAmountTotal) + parseFloat(doc.InvoiceAmount);
                 referalCommissionTotal = parseFloat(referalCommissionTotal) + parseFloat(doc.ReferralCommission);
                 developerCommissionTotal= parseFloat(developerCommissionTotal) + parseFloat(doc.DeveloperCommission);
            });
        InvoiceList.sort(SortByID);
        InvoiceList = InvoiceList.slice(pageNo * numberOfRecords, pageNo * numberOfRecords + numberOfRecords);
        // Check the feed and if empty, set the body to 'no docs found', 
        // else take 1st element from feed
        getContext().getResponse().setBody(JSON.stringify({ InvoiceList, count, invoiceAmountTotal, referalCommissionTotal, developerCommissionTotal }));

    });


}
function SortByID(a, b) {
    var aName = a.UpdatedOn.toLowerCase();
    var bName = b.UpdatedOn.toLowerCase();
    return ((aName < bName) ? -1 : ((aName > bName) ? 1 : 0));
}
if (!isAccepted) throw new Error('The query was not accepted by the server.');
}

任何帮助将不胜感激..

如果您想一次取回全部 250,您需要使用 pageSize 字段填充 queryDocuments() 的选项参数。它是该函数调用的可选第三个参数。没有它,这个 server-side API 将默认为 100。

您还可以将 pageSize 设置为 -1 以获得所有文档。但是,对于 server-side 存储过程,我不建议这样做。相反,您需要使用延续令牌来处理分页。如果您希望它非常健壮,您还需要处理存储过程的过早关闭。