Maxwell_Dncey
Maxwell_Dncey

Reputation: 105

How can I get the version information of mongodb through pymongo or other python tools?

As the title. It seems that pymongo does not support, is there any other easy way to get.

Upvotes: 4

Views: 3480

Answers (2)

Maxwell_Dncey
Maxwell_Dncey

Reputation: 105

from pymongo import MongoClient

client = MongoClient(uri)

version = client.server_info()["version"]
version_array = client.server_info()["versionArray"]

print(version)
>>> '4.4.4'
print(version_array)
>>> [4, 4, 4, 0]

Upvotes: 6

miwin
miwin

Reputation: 1215

Once you are connected to your MongoDB via pymongo you can retrieve the version with:

db.command({'buildInfo':1})['version']

This would return e.g. '4.4.5'.

Upvotes: 4

Related Questions