コード例 #1
0
 private MongoClient CreateClient(MongoClientOptions options)
 {
     if (options.Url != null)
     {
         return(new MongoClient(options.Url));
     }
     return(new MongoClient(options.Settings));
 }
コード例 #2
0
 private async void Initialize(string databaseName, MongoClientOptions options)
 {
     if (string.IsNullOrEmpty(databaseName))
     {
         throw new ArgumentNullException("Database", "Your connection string must contain a database name");
     }
     if (_database != null)
     {
         throw new InvalidOperationException("Database connection is already initialized!");
     }
     try {
         _database = CreateClient(options).GetDatabase(databaseName);
         await ConfigurateAsync();
     } catch (Exception) {
         _database = null;
         throw;
     }
 }