Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skip and top functions for paging in DocumentDB

Can we do Skip and Top for paging like

SELECT TOP 10 PostId FROM Contacts

in DocumentDB ?

like image 225
madhu Avatar asked Dec 18 '14 10:12

madhu


2 Answers

Not sure what language you are working with or if you still need an answer but This is what I did to work around the TOP X until the feature is implemented.

I wanted to run a query and only grab the top 1 from the results w/o returning the entire collection. In the SDK I found the feedOptions object that was able to only select the TOP X that i needed.

The code:

.NET (MSDN):

       var options = new FeedOptions { MaxItemCount = 1 };
       var query = _documentclient.CreateDocumentQuery<MyObject>(this.MyObjects.SelfLink, "SELECT * FROM MyObject m WHERE m.Enabled = false", options).AsDocumentQuery();
       var topItem = (await query.ExecuteNextAsync<MismatchedAnswer>()).FirstOrDefault();

Node.js (GITHUB)

client.queryDocuments(collectionSelfLink, "SELECT * FROM MyObject m WHERE m.Enabled = false",{maxItemCount: 1}).nextItem(function(err, element){
    console.log([err, firstItem]);
  })
like image 112
Dewseph Avatar answered Jan 03 '23 10:01

Dewseph


Skip and Top are not implemented yet.

Please voice your opinion by voting for this feature on the Azure Feedback forum:

http://feedback.azure.com/forums/263030-documentdb/suggestions/6350987--documentdb-allow-paging-skip-take

like image 22
Andrew Liu Avatar answered Jan 03 '23 10:01

Andrew Liu