宇宙的延续令牌 [英] Continuation Token for cosmos

查看:87
本文介绍了宇宙的延续令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Team,

Hello Team,

我使用cosmos db来存储方案少数据&我使用的宇宙C#API 使用LINQ Microsoft.Azure.Documents.Client.DocumentClient查询宇宙DB和获取数据

I am using cosmos db for storing scheme less data & i'm using cosmos c# api Microsoft.Azure.Documents.Client.DocumentClient using linq to query cosmos db and get the data

现在我已经对它失去了的记录,如100K,所以我不能马上带来所有东西,我使用了延续令牌的概念,这样我就可以执行分页以逐页获取数据

Now i have lost of records in it like 100K, so i can't bring everything at once, i had used the concept of continuation token so that i can perform pagination to get the data page by page

这里是代码片段 

And here is the code snippet 

var pagesize = 10

var pagesize = 10

var token = null;

var token = null;

var partitionKey = null;

var partitionKey = null;

表达式< Func< T,bool>> predicate =(doc => doc.Id ='SomeId')//我在这里使用过泛型,请不要考虑这个

Expression<Func<T, bool>> predicate = (doc => doc.Id = 'SomeId') //I've used generics here, pls don't consider this

  IQueryable的< T> querySetup = null;

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; IDocumentQuery< T> query = null;



  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; querySetup = _client.CreateDocumentQuery< T>(

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;连杆,

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;新FeedOptions()

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;         {

             &NBSP;&NBSP;&NBSP; EnableCrossPartitionQuery =真,

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; MaxItemCount = pageSize,

                RequestContinuation = token,

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;!?PartitionKey = String.IsNullOrEmpty(partitionKey)新PartitionKey(PA rtitionKey):null

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; });
$




  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; query = querySetup.AsDocumentQuery();

  IQueryable<T> querySetup = null;
            IDocumentQuery<T> query = null;

            querySetup = _client.CreateDocumentQuery<T>(
                          link,
                          new FeedOptions()
                          {
                              EnableCrossPartitionQuery = true,
                              MaxItemCount = pageSize,
                              RequestContinuation = token,
                              PartitionKey = !String.IsNullOrEmpty(partitionKey) ? new PartitionKey(partitionKey) : null
                          });


            query = querySetup.AsDocumentQuery();

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; querySetup = querySetup.Where(谓词);

            querySetup = querySetup.Where(predicate);

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; var result = await query.ExecuteNextAsync< T>();

            var result = await query.ExecuteNextAsync<T>();

所以当我们点击&看看querySetup它生成linq到cosmos查询就好像

So when we hit & see the querySetup its generate the linq into cosmos query like

从root选择* WHERE root.Id ='BLABLA'

Select * from root WHERE root.Id = 'BLABLA'

所以我的问题是是否有任何可行性来立即获得所有延续令牌,因为我们可以说例如

So my question is that is there any feasibility to get all the continuation token at once, because lets say for example

我有100条记录,这100条记录分为10个项目的每个页面

i have 100 records and these 100 records are divided into pages each of 10 items

1 - 10 - 第一页(以续订令牌返回)

1 - 10 - 1st Page (return with Continuation token)

11 - 20 - 第二页 (以续订令牌返回)......

11 - 20 - 2nd Page (return with Continuation token) ......

所以我每次都要向宇宙查询以获得下一个延续令牌 

So every time I've to query to cosmos to get the next continuation token 

所以,如果我要从第1页跳到第7页,我必须迭代所有页面直到6,然后才会得到7。

So lets say if I've to jump from 1st Page to 7th Page, i have to iterate all the page till 6 and then will get 7.

所以我的观点是如何直接跳到第7页而不重复所有。

So my point is how can i jump directly to 7th Page without iterating all.

或者让我这样说是否有任何可行性来立即获取所有延续令牌以便我知道7page的延续令牌以便我可以跳转并获得它。

Or let me put it in this way is there any feasibility to get all the continuation token at once so that i know the continuation token of 7page so that i can jump and get it.

推荐答案

您好GhostLoft1992,

Hi GhostLoft1992,


OFFSET LIMIT
子句现在可用,可以用来控制SQL API的结果集。

The OFFSET LIMIT clause is now available and can be leveraged to control the result set with the SQL API.

" 当OFFSET LIMIT与ORDER BY子句一起使用时,结果集是通过跳过并接受订购的
值生成的。"

没有办法直接跳到已通过ContinuationToken分页的长时间运行查询的第7页。但是,有一些方法可以优化搜索并控制结果。 

There is no way to directly skip to page 7 of a long running query that has been paginated via the ContinuationToken. There are, however, ways to refine the search and control the results. 

如果您有其他问题,请现在就联系我们。

Please lets us now if you have additional questions.


这篇关于宇宙的延续令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆