Skip and top swap functions in DocumentDB

We can make Skip and Top for paging as

SELECT TOP 10 PostId FROM Contacts

in DocumentDB?

+6
source share
2 answers

Not sure what language you work in, or if you still need an answer, but this is what I did to work with TOP X until the function is implemented.

I wanted to run a query and only grab the top 1 of the results without returning the entire collection. In the SDK, I found a feedOptions object that was able to select only the TOP X that I need.

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

Skip and Top are not yet implemented.

Please express 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

+3
source

Source: https://habr.com/ru/post/979846/


All Articles