C# Azure DocumentDB C SDK使用带有跳过记录的MaxItemCount
在CreateDocumentQuery中,我使用MaxItemCount,然后使用HasMoreResults和ExecuteExtAsync,这在其他文章中已经描述过 我的问题是,有时——特别是在对DocumentDB进行了大量更新之后——遍历每个文档会产生一些随机结果,多达一半的文档会被忽略 只有在查询设置中包含SQL查询时才会发生这种情况,因为我只需要处理一些字段/列。如果我允许所有字段返回,它将100%工作。但这是低效的,因为我只导出了几个列,而且有将近一百万条记录 我需要使用C,因为它是一个与其他C模块相连的计划作业 是否有人能够使用分页一致地循环遍历大型集合 下面的代码摘录-包含sql-如果我从查询中删除sql,则没有问题C# Azure DocumentDB C SDK使用带有跳过记录的MaxItemCount,c#,azure,azure-cosmosdb,C#,Azure,Azure Cosmosdb,在CreateDocumentQuery中,我使用MaxItemCount,然后使用HasMoreResults和ExecuteExtAsync,这在其他文章中已经描述过 我的问题是,有时——特别是在对DocumentDB进行了大量更新之后——遍历每个文档会产生一些随机结果,多达一半的文档会被忽略 只有在查询设置中包含SQL查询时才会发生这种情况,因为我只需要处理一些字段/列。如果我允许所有字段返回,它将100%工作。但这是低效的,因为我只导出了几个列,而且有将近一百万条记录 我需要使用C,因为
sql = "select d.field1, d.field2 from doc d";
var query = client.CreateDocumentQuery("dbs/" + database.Id + "/colls/" + documentCollection.Id, sql
new FeedOptions { MaxItemCount = 1000 }
).AsDocumentQuery();
while (query.HasMoreResults)
{
FeedResponse<Document> res;
while (true)
{
try
{
res = await query.ExecuteNextAsync<Document>();
break; // success!
}
catch (Exception ex)
{
if (ex.Message.IndexOf("request rate too large") > -1)
{
// DocumentDB is under pressure - wait a while and retry - this will resolve eventually
System.Threading.Thread.Sleep(5000);
}
else
{
errorcount++;
throw ex;
}
}
}
if (res.Any())
{
foreach (var liCurrent in res)
{
try
{
// Convert the Document to a CSV line item
// DO THE FILE LINE CREATION HERE
fileLineItem = "test";
// Write the line to the file
writer.WriteLine(fileLineItem);
}
catch (Exception ex)
{
errorcount++;
throw ex;
}
totalrecords++;
}
}
}
Amab指出的解决方案是将一致性级别设置为一致。我以前做过这件事,但后来我删除并重新创建了这个收藏。创建集合时,默认设置为惰性。因此,您需要在创建时指定它,或者稍后修改它
感谢Amab您的数据库的一致性级别是多少?有关一致性级别的更多信息,请查看“谢谢”-将一致性更改为一致性而不是懒惰似乎已经解决了问题。您应该将此作为答案发布。可能对其他人有用。