1

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

Line 182:

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

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!

Tom
  • 129
  • 3
  • 11

2 Answers2

3

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.

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.

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");

in order to get 1000 documents instead of 100.

Ralf Bönning
  • 14,515
  • 5
  • 49
  • 67
0

I'm just guessing here, but it might be worth a shot. Here's the documentation from MSDN that describes the List action:

https://learn.microsoft.com/en-us/rest/api/documentdb/list-documents

In the "Headers" section under "Response" it is mentioned that you might get an optional token in the header "x-ms-continuation". Based on the description you have to issue another GET request with this token specified to get the other elements of the result set.

Can you check whether you get a header like this in the response? If so, you can issue another get request with this token specified (see the same documentation page under "Request").

Akos Nagy
  • 4,201
  • 1
  • 20
  • 37