Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get list of all collections in a DocumentDB document?

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.

like image 599
Ankit Avatar asked Dec 12 '14 07:12

Ankit


1 Answers

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

like image 117
Andrew Liu Avatar answered Sep 28 '22 08:09

Andrew Liu