Pyotreq
Pyotreq

Reputation: 156

Receive all documents from database Azure DocumentDB

I try to receive all documents from Azure DocumentDB database. I have found example which indicate my problem but it doesn't work. https://github.com/Microsoft/azure-docs/blob/master/articles/documentdb/documentdb-sharding.md#create-queries-against-all-collections-in-the-database

My code (C#):

var client = new DocumentClient(new Uri(endPointUrl), authorizationKey);
var database = await client.ReadDatabaseAsync(UriFactory.CreateDatabaseUri(DatabaseId));
var documents = client.CreateDocumentQuery(database.Resource.SelfLink).ToList();

and I CreateDocumentQuery the exception:

Message: {"Server could not parse the Url."}; Error: {{ "code": "NotFound", "message": "Server could not parse the Url." }};

So, Can I receive documents from many collections in once query?

Upvotes: 1

Views: 371

Answers (1)

Gaurav Mantri
Gaurav Mantri

Reputation: 136306

So, Can I receive documents from many collections in once query?

Simple answer is No. You can't do that.

What you would need to do is first list all collections in a database and then fetch documents from each collection separately. For each collection, you will need to execute separate queries.

Also, please note that if you have more than 1000 documents in a collection, a single request will return a maximum of 1000 documents. In this case, you will get a continuation token back from the service. You would need to resend the query with this continuation token to get next set of data from that collection. You would repeat this process till the time service returns you a continuation token in response. Absence of continuation token would imply that all documents from a collection has been fetched. Then you can move on to next collection in your database (if you're doing sequential execution).

Upvotes: 2

Related Questions