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

Viewed 989

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

2 Answers

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'.

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]
Related