如何使用Azure DocumentDB REST API获得100多个查询结果 [英] How to get more than 100 query results with Azure DocumentDB REST API

查看:81
本文介绍了如何使用Azure DocumentDB REST API获得100多个查询结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在下面关注Azure DocumentDB的示例.在该示例中,C#代码在DocumentDB中查询文档.

I am following a sample for Azure DocumentDB below. In the sample, C# code queries for documents in the DocumentDB.

https://github.com/Azure/azure-documentdb-dotnet/blob/master/samples/rest-from-.net/Program.cs

第182行:

var qry = new SqlQuerySpec { query = "SELECT * FROM root" }; 
var r = client.PostWithNoCharSetAsync(new Uri(baseUri, resourceLink), qry).Result; 

问题在于结果"r"仅包含前100个文档.如果我使用客户端SDK ,则可以获得100多个.尝试使用流,但到目前为止还没有运气.任何帮助将不胜感激!

The problem is the result 'r' only contains the first 100 documents. If I use the Client SDK, I can get more than 100. I tried using stream, but had no luck so far. Any help would be appreciated!

推荐答案

对于SQL查询,如果结果集太大,则按段返回结果.默认情况下,结果以100个项目或1 MB(以先达到限制为准)的块形式返回.

For a SQL query the results are returned in segments if the result set is too large. The results are returned in chunks of 100 items or 1 MB (whichever limit is hit first) by default.

您可以使用延续标记来获取每个片段.或者,您可以在请求中设置 x-ms-max-item-count 自定义标头,以将限制增加到适当的值.

You can either use continuation tokens to get each segment after another. Or you set the x-ms-max-item-count custom header in a request to increase the limit to an appropriate value.

您可以查看 REST API 了解更多详细信息.

You can have a look the the REST API for further details.

对于示例程序,您必须添加行

For the sample program you have to add the line

client.DefaultRequestHeaders.Add("x-ms-max-item-count", "1000");

以获取1000个文档而不是100个文档.

in order to get 1000 documents instead of 100.

这篇关于如何使用Azure DocumentDB REST API获得100多个查询结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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