Created
March 31, 2015 22:50
-
-
Save mizrael/64169d08b38b93e3d4a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static MongoDatabase Connect(string connectionString) | |
{ | |
if (string.IsNullOrWhiteSpace(connectionString)) | |
throw new System.ArgumentNullException("invalid connection string"); | |
var mongoConnStr = MongoUrl.Create(connectionString); | |
MongoClient client = new MongoClient(mongoConnStr); | |
MongoServer server = client.GetServer(); | |
if (server.State == MongoServerState.Disconnected) | |
server.Connect(); | |
return server.GetDatabase(mongoConnStr.DatabaseName); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment