C# 如何从 Azure Cosmos 获取数据库列表

C# How to get list of database from Azure Cosmos

我想知道是否可以从 Azure Cosmos 获取所有数据库的列表。我看到一个可能的解决方案是 here 。但是,如果我只知道连接字符串,还有什么办法吗?

试试下面的方法。它利用 v3 of Cosmos DB .Net SDK.

            CosmosClient client = new CosmosClient("cosmos-db-connection-string");
            using (FeedIterator<DatabaseProperties> iterator = client.GetDatabaseQueryIterator<DatabaseProperties>())
            {
                while (iterator.HasMoreResults)
                {
                    foreach (DatabaseProperties db in await iterator.ReadNextAsync())
                    {
                        Console.WriteLine(db.Id);
                    }
                }
            }

您可以在此处找到更多示例:https://github.com/Azure/azure-cosmos-dotnet-v3/tree/master/Microsoft.Azure.Cosmos.Samples