Dmitri Dmitri - 2 months ago 11
PHP Question

How to get the version of mongodb from php

I need a way to display a version of Mongo database in the php website.
For example, I want to show something like "powered by MongoDB version 2.2.6"

I cannot find a way to find out the version of database that php mongoClient is connected to.

I'm sure that is a way to do this. Does anyone know how?

$mongo = new \Mongo();

$admin = $mongo->admin;

$infos= $admin->command(array('buildinfo'=>true));
$version = $infos['version'];


(You need to be admin to show it)

UPDATE : Without authentication, you can check it by using a MongoDB instance.

$c = new \MongoClient();
$db = 'yourdbname';

$mongo = new \MongoDB($c, $db);

$mongodb_info = $mongo->command(array('serverStatus'=>true));
$mongodb_version = $mongodb_info['version'];