8

I have created a lot of collections in a DocumentDB database. How can I retrieve the list of existing collections in the database?

I have just started exploring DocumentDb from the official documentation.

Ankit
  • 2,448
  • 3
  • 20
  • 33

1 Answers1

13

The short answer is: you can't retrieve a list of collections inside a document. You can, however, retrieve a list of collection inside a database.

Here's a look at the DocumentDB resource model: enter image description here

Looking at the DocumentDB resource model - databases contain collections, which in turn contain stored procedures, triggers, UDFs, and documents.

You can query a list of collections under a given database by using the DocumentDB Client or the REST API. Here's an example in .NET:

DocumentClient client = new DocumentClient(new Uri(endpoint), authKey);

Database database = client.CreateDatabaseQuery("SELECT * FROM d WHERE d.id = \"[YOUR_DATABASE_ID]\"").AsEnumerable().First();

List<DocumentCollection> collections = client.CreateDocumentCollectionQuery((String)database.SelfLink).ToList();

References:

DocumentDB Resource Model and Concepts

DocumentDB .NET Code Samples

Andrew Liu
  • 8,045
  • 38
  • 47