tomfly
tomfly

Reputation: 53

MongoDB .net driver - Get MongoDB server version

I'm using MongoDB .net driver v2.10 and want to know, how I'm able to determine MongoDB version of connected MongoDB Atlas server, for example v4.2.5.

Thank you in advance for your support!

Upvotes: 4

Views: 1107

Answers (1)

mickl
mickl

Reputation: 49945

MongoDB database instance (IMongoDatabase interface in .NET) offers .runCommand() and you can run buildInfo to get server veresion:

var version = database.RunCommand(
                new BsonDocumentCommand<BsonDocument>(new BsonDocument() {{"buildInfo", 1}}))
                ["version"];

Upvotes: 4

Related Questions