Skip to content

Commit

Permalink
MongoDB: Use database from connection string when set (#347)
Browse files Browse the repository at this point in the history
Will still default to "MiniProfiler" when not set but otherwise will use the database as defined from the connection string.
  • Loading branch information
Turnerj authored and NickCraver committed Dec 10, 2018
1 parent 42393f5 commit 1801371
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/MiniProfiler.Providers.MongoDB/MongoDbStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ public MongoDbStorage(string connectionString)
BsonClassMapFields();
}

_client = new MongoClient(connectionString);
var url = new MongoUrl(connectionString);
var databaseName = url.DatabaseName ?? "MiniProfiler";

_client = new MongoClient(url);
_collection = _client
.GetDatabase("MiniProfiler")
.GetDatabase(databaseName)
.GetCollection<MiniProfiler>("profilers");
}

Expand Down
3 changes: 2 additions & 1 deletion tests/MiniProfiler.Tests/Storage/MongoDbStorageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public static class MongoDbStorageExtensions
/// <param name="storage">The storage to drop schema for.</param>
public static void DropDatabase(this MongoDbStorage storage)
{
storage.GetClient().DropDatabase("MiniProfiler");
var url = new MongoDB.Driver.MongoUrl(TestConfig.Current.MongoDbConnectionString);
storage.GetClient().DropDatabase(url.DatabaseName);
}
}
}

0 comments on commit 1801371

Please sign in to comment.