madhu
madhu

Reputation: 103

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 ?

Upvotes: 6

Views: 2482

Answers (2)

Dewseph
Dewseph

Reputation: 155

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]);
  })

Upvotes: 4

Andrew Liu
Andrew Liu

Reputation: 8119

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

Upvotes: 3

Related Questions