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.
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.
简短的回答是:您无法检索文档中的集合列表。但是,您可以检索数据库中的集合列表。
下面看一下 DocumentDB 资源模型:
查看 DocumentDB 资源模型 - 数据库包含集合,而集合又包含存储过程、触发器、UDF 和文档。
您可以使用 DocumentDB 客户端或 REST API 查询给定数据库下的集合列表。这是 .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();
参考: