gpt4 book ai didi

azure - 如何在 cosmosDB 中进行分页?

转载 作者:行者123 更新时间:2023-12-02 20:11:49 25 4
gpt4 key购买 nike

我正在尝试使用 Cosmos 数据库进行分页,但跳过命令出现问题。

var resultDTO = this.client.CreateDocumentQuery<AuditDTO>(
UriFactory.CreateDocumentCollectionUri(idDatabase, idCollection), queryOptions)

.Skip(2*1)
.Take(amount)
.AsEnumerable()
.ToList();

你知道如何实现吗?

最佳答案

目前支持分页,基于continuation token.

以下示例说明了一种根据所需页码、页面大小和继续标记查询文档的方法:

private static async Task<KeyValuePair<string, IEnumerable<CeleryTask>>> QueryCosmosDBPage(int pageSize, string continuationToken)
{
DocumentClient documentClient = new DocumentClient(new Uri("https://{CosmosDB/SQL Account Name}.documents.azure.com:443/"), "{CosmosDB/SQL Account Key}");

var feedOptions = new FeedOptions {
MaxItemCount = pageSize,
EnableCrossPartitionQuery = true,

// IMPORTANT: Set the continuation token (NULL for the first ever request/page)
RequestContinuation = continuationToken
};

IQueryable<CeleryTask> filter = documentClient.CreateDocumentQuery<CeleryTask>("dbs/{Database Name}/colls/{Collection Name}", feedOptions);
IDocumentQuery<CeleryTask> query = filter.AsDocumentQuery();

FeedResponse<CeleryTask> feedRespose = await query.ExecuteNextAsync<CeleryTask>();

List<CeleryTask> documents = new List<CeleryTask>();
foreach (CeleryTask t in feedRespose)
{
documents.Add(t);
}
return new KeyValuePair<string, IEnumerable<CeleryTask>>(feedRespose.ResponseContinuation, documents);
}

关于azure - 如何在 cosmosDB 中进行分页?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53411376/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com