var client = new MongoClient("mongodb://localhost:27017"); var database = client.GetDatabase("myNewDatabase");
var client = new MongoClient("mongodb://localhost:27017"); var database = client.GetDatabase("myExistingDatabase"); if (database != null) { Console.WriteLine("The database exists!"); }
var client = new MongoClient("mongodb://localhost:27017"); var database = client.GetDatabase("myDatabase"); database.CreateCollection("myNewCollection");The package library used in this example is the official MongoDB .NET driver, which can be installed via NuGet. The class MongoDatabase is part of the MongoDB.Driver namespace in the MongoDB.Driver.Core package.