Reputation: 36280
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?
Upvotes: 1
Views: 2813
Reputation: 2602
$server_status = db->command(array('serverStatus' => TRUE));
will give you lots of information including version
(you need to be admin to run it)
Upvotes: 0
Reputation: 2903
$mongo = new \Mongo();
$admin = $mongo->admin;
$infos= $admin->command(array('buildinfo'=>true));
$version = $infos['version'];
die($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'];
die($mongodb_version);
Upvotes: 4
Reputation: 13649
Check out the serverStatus
command:
http://docs.mongodb.org/manual/reference/command/serverStatus/
If you're using the PHP driver, check out:
http://php.net/manual/en/mongodb.command.php
to see how you can run that command.
Upvotes: 1
Reputation: 11845
I am not sure, maybe this:
<?php
$v = `mongo --version`;
print_r($v);
?>
Upvotes: 0