Q:

MongoDB: Getting the list of all databases? 

How do I list all databases for a connection using Mongo C# Driver? 

A:

Very easily:
var server = MongoServer. Create("mongodb://localhost/?safe=true");
var databaseNames = server. GetDatabaseNames();

A:

The MongoServer class was deprecated in version 2.0.0. 
You can use ListDatabasesAsync
using (var cursor = await client. ListDatabasesAsync())
{
    await cursor. ForEachAsync(d => Console. WriteLine(d. ToString()));
}

A:

Working Solution:
MongoClient client = new MongoClient("mongodb://localhost:27017");
using (IAsyncCursor<BsonDocument> cursor = client. ListDatabases())
{
    while (cursor. MoveNext())
    {
        foreach (var doc in cursor. Current)
        {
            Console. WriteLine(doc["name"]); // database name
        }
    }
}

