Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 788
Maxwell_Dncey Avatar asked Nov 15 '25 07:11

Maxwell_Dncey


2 Answers

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]
like image 162
Maxwell_Dncey Avatar answered Nov 17 '25 21:11

Maxwell_Dncey


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

like image 41
miwin Avatar answered Nov 17 '25 21:11

miwin