Reputation: 147
I wonder there is anyway to get a list of all database from Azure Cosmos. I see a possible solution is here . However if I only know the Connection String, is there anyway to do it ?
Upvotes: 0
Views: 1596
Reputation: 136216
Try something like below. It makes use of 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);
}
}
}
You can find more samples here: https://github.com/Azure/azure-cosmos-dotnet-v3/tree/master/Microsoft.Azure.Cosmos.Samples.
Upvotes: 3