Azure cosmosdb C#获取Cosmos数据库中的容器列表

Azure cosmosdb C#获取Cosmos数据库中的容器列表,azure-cosmosdb,Azure Cosmosdb,如何使用C获取Cosmos数据库的容器列表# GetContainers()没有选项。您可以通过以下方式存档: 专用只读CosmosClient数据库客户端; 公共宇宙数据库管理器(宇宙客户端数据库客户端) { this.databaseClient=databaseClient; } 公共异步任务GetContainer(CosmosDbConfiguration配置) { Database=this.databaseClient.GetDatabase(configuration.Datab

如何使用C获取Cosmos数据库的容器列表#


GetContainers()没有选项。

您可以通过以下方式存档:

专用只读CosmosClient数据库客户端;
公共宇宙数据库管理器(宇宙客户端数据库客户端)
{
this.databaseClient=databaseClient;
}
公共异步任务GetContainer(CosmosDbConfiguration配置)
{
Database=this.databaseClient.GetDatabase(configuration.Database);
FeedIterator迭代器=数据库.GetContainerQueryIterator();
FeedResponse containers=await iterator.ReadNextAsync().ConfigureAwait(false);
foreach(容器中的var容器)
{
//你想用这个容器做什么就做什么
}
}
就你而言:

CosmosClient客户端2=新的CosmosClient(“https://MYCOSMOS.documents.azure.com:443/“,”kpWBLj8jfN0qDPsdfsg1Amng==”;
Database Database=this.client2.GetDatabase(configuration.Database);
FeedIterator迭代器=数据库.GetContainerQueryIterator();
FeedResponse containers=await iterator.ReadNextAsync().ConfigureAwait(false);
foreach(容器中的var容器)
{
//例如,container.id将返回容器的名称
}
var client2 = new CosmosClient("https://MYCOSMOS.documents.azure.com:443/", "kpWBLj8jfN0qDPsdfsg1Amng==");
client2.GetDatabase("").GetContainer("");