C#获取Cosmos数据库中的容器列表 [英] C# Get list of containers in a Cosmos Database
本文介绍了C#获取Cosmos数据库中的容器列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用C#获取Cosmos数据库的容器列表
How do I get list of container for a Cosmos Database using C#
var client2 = new CosmosClient("https://MYCOSMOS.documents.azure.com:443/", "kpWBLj8jfN0qDPsdfsg1Amng==");
client2.GetDatabase("").GetContainer("");
没有 GetContainers()
推荐答案
您可以通过以下方式对此进行存档:
You can archive this by this way:
private readonly CosmosClient databaseClient;
public CosmosDbManager(CosmosClient dataBaseClient)
{
this.databaseClient = dataBaseClient;
}
public async Task GetContainer(CosmosDbConfiguration configuration)
{
Database database = this.databaseClient.GetDatabase(configuration.Database);
FeedIterator<ContainerProperties> iterator = database.GetContainerQueryIterator<ContainerProperties>();
FeedResponse<ContainerProperties> containers = await iterator.ReadNextAsync().ConfigureAwait(false);
foreach (var container in containers)
{
// do what you want with the container
}
}
在您的情况下:
CosmosClient client2 = new CosmosClient("https://MYCOSMOS.documents.azure.com:443/", "kpWBLj8jfN0qDPsdfsg1Amng==");
Database database = this.client2.GetDatabase(configuration.Database);
FeedIterator<ContainerProperties> iterator = database.GetContainerQueryIterator<ContainerProperties>();
FeedResponse<ContainerProperties> containers = await iterator.ReadNextAsync().ConfigureAwait(false);
foreach (var container in containers)
{
// for examploe container.id will return the name of your container
}
这篇关于C#获取Cosmos数据库中的容器列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文