Skip to content

Commit

Permalink
Merge pull request #1 from ArtemNizelnyk/master
Browse files Browse the repository at this point in the history
MongoServer.BuildInfo always null at start.
  • Loading branch information
ob1dev authored May 1, 2017
2 parents 9571a46 + 8903a0e commit 7c4bfa4
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/TestMongoDBConnection/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Configuration;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;

namespace TestMongoDBConnection
Expand All @@ -28,7 +29,7 @@ private static void Main()
}

private static void TestConnectionString(string name, string connectionString)
{
{
Log.AppendLine();
Log.AppendLine($"====== Test Date: {DateTime.Now.ToString(CultureInfo.InvariantCulture)} ======");
Log.AppendLine();
Expand All @@ -38,11 +39,13 @@ private static void TestConnectionString(string name, string connectionString)
try
{
MongoClient client = new MongoClient(connectionString);

var versionString = client.GetServer().BuildInfo.VersionString;
var mongoServer = client.GetServer();
mongoServer.Connect();
var buildInfos = mongoServer.Instances.Select(x => x.BuildInfo);
var versionStrings = buildInfos.Select(x => x.VersionString);

Log.AppendLine();
Log.AppendLine($"MongoDB version: {versionString}.");
Log.AppendLine($"MongoDB version: {string.Join(" | ", versionStrings)}.");
Log.AppendLine("Connect is successful.");
Log.AppendLine();
}
Expand All @@ -61,7 +64,7 @@ private static void DumpLog(StringBuilder log)
using (StreamWriter writer = new StreamWriter(fileName))
{
writer.Write(log);
}
}
}
}
}

0 comments on commit 7c4bfa4

Please sign in to comment.