Azure-cosmos-dotnet-v2: Method Skip is not supported while querying Cosmos DB

Created on 2 Nov 2017  路  18Comments  路  Source: Azure/azure-cosmos-dotnet-v2

Hi,

While i am trying to implement pagination in the cosmos db query. i am getting this error:

Microsoft.Azure.Documents.Client: Method 'Skip' is not supported.

Here is my C# code:

IDocumentQuery<T> query = client.CreateDocumentQuery<T>(
                UriFactory.CreateDocumentCollectionUri(DatabaseId, CollectionId),
                new FeedOptions { MaxItemCount = -1 })
                .Where(predicate)
                .Skip(pageIndex)
                .Take(pageSize) 
                .AsDocumentQuery();

How would i fix this? Thanks.

Most helpful comment

      Ive done paging fine without Skip.

Please enlighten us.

All 18 comments

@bchong95 can you please take a look?

Hi,

We currently do not support Skip in SQL queries (and thus we don't support it for LINQ).

The workaround is to leverage the Continuation Token retrieved from executing the query.

This blog post talks about how this can be achieved:

http://www.kevinkuszyk.com/2016/08/19/paging-through-query-results-in-azure-documentdb/

Note that this method still consumes RUs to get to the skip point that you are interested in, so the recommendation is to keep these continuation tokens around for as long as possible. This means that if you have a webpage of paginated results, then you can periodically drain the query from start to finish and save the continuation tokens generated to have skip points.

In the future we will support client side skips.

Thank you,

Thanks @bchong95. I am checking this solution out and will get back to you.

This works. Thanks a lot @bchong95 :-) you can close this issue.

I have seen on UserVoice that adding Skip and Take are being worked on but I cannot seem to find the github issue for that feature, is there one? thank you

Starting my pagination journey for CosmosDB today, this does seem alittle painful not having skip.

Take is already present, you can limit the number or items to get.
As for Skip, first we were upset that there is no Skip, but later we realized that Skip would consume significant amount of RUs and such solution would not work in general case if you have thousands or millions documents.

So we allow pagination only by continuation token, e.g. virtual scroll etc. If you want to jump to page number 1000 - just use more specific query, like date time etc.

This is a serious shortcoming. Integrating with Material UI pagination seems too hard to be worth it.

I have to say, DocumentDB is missing a lot of features that I've taken for granted in RavenDB. Not affiliated with them, just a fan since RavenDB 2.0.

Here is the UserVoise issue for missing Skip This is really something I expected would be baked in by now.

Ive done paging fine without Skip.

      Ive done paging fine without Skip.

Please enlighten us.

@melzoghbi Can you please reopen this? The issue as stated has not been resolved and I didn't see any open issues this is a duplicate of. Based on the user voice link above, it's being worked on so it would be nice to be able to track it here.

Any news on this?

Wow, I'm really surprised this is not yet available. Any plans to work on this feature at all?

offset/limit (skip/take) is now available in cosmosdb
https://docs.microsoft.com/en-us/azure/cosmos-db/how-to-sql-query#OffsetLimitClause

UPDATE
The .net sdk indicated that I need to filter on my partition key, which makes sense. When I did that in the emulator, limit worked as expected. So just seems the emulator just didn't error like the .net sdk did.


Am I missing something silly, or does the emulator not support limit correctly? Was expecting 1 result instead of 2.
image

skip/take (linq) is being implemented in the new v3 cosmos client
https://github.com/Azure/azure-cosmos-dotnet-v3/issues/8

not sure if it will land in the current v2 @bchong95 ?

Was this page helpful?
0 / 5 - 0 ratings