DocumentDB paging with many collections -
lets have 2 collections , there 10 documents in each collection. recommended way paging if want retrive max 15 documents?
when run code below 20 results. begins requesting first collection returnes 10 , second returns 10 should return 5 since maxitemcount 15.
var batches = new list<ienumerable<t>>(); var feedoptions = new feedoptions { maxitemcount = 15 }; var docquery = client.createdocumentquery<t>(database.selflink, feedoptions) .where(predicate).asdocumentquery(); { var batch = await docquery.executenextasync<t>(); batches.add(batch); } while (docquery.hasmoreresults); var docs = batches.selectmany(b => b).take(maxitemcount.value); return docs;
maxitemcount controls number of results per page, not total results returned. reduce total number of results, change while clause check e.g., (docquery.hasmoreresults && batch.length <= maxitemcount.value).
hope helps.
Comments
Post a Comment