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.
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:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With