Can we do Skip and Top for paging like
SELECT TOP 10 PostId FROM Contacts
in DocumentDB ?
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]);
})
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With