I'm currently trying to retrieve the statistics of a mongodb by php. I already found the way to run the command (https://stackoverflow.com/a/11650724/2889265), but than executing it, the response is completly different to the expected result of executing db.stats() directly on the database. Here's what I got:
Result PHP $this->database->command(array('dbStats' => 1));:
MongoDB\Driver\Cursor Object
(
[database] => dev
[collection] =>
[query] =>
[command] => MongoDB\Driver\Command Object
(
[command] => stdClass Object
(
[dbStats] => 1
)
)
[readPreference] => MongoDB\Driver\ReadPreference Object
(
[mode] => primary
)
[isDead] =>
[currentIndex] => 0
[currentDocument] =>
[server] => MongoDB\Driver\Server Object
(
[host] => xxx.xxx.xxx.xxx
[port] => 27017
[type] => 1
[is_primary] =>
[is_secondary] =>
[is_arbiter] =>
[is_hidden] =>
[is_passive] =>
[last_is_master] => Array
(
[ismaster] => 1
[maxBsonObjectSize] => 16777216
[maxMessageSizeBytes] => 48000000
[maxWriteBatchSize] => 1000
[localTime] => MongoDB\BSON\UTCDateTime Object
(
[milliseconds] => 1498465564742
)
[maxWireVersion] => 2
[minWireVersion] => 0
[ok] => 1
)
[round_trip_time] => 12
)
)
Result db.stats()
{
"db" : "dev",
"collections" : 21,
"objects" : 7153120,
"avgObjSize" : 818.2133580871005,
"dataSize" : 5852778336,
"storageSize" : 6882250752,
"numExtents" : 71,
"indexes" : 26,
"indexSize" : 866189968,
"fileSize" : 8519680000,
"nsSizeMB" : 16,
"dataFileVersion" : {
"major" : 4,
"minor" : 5
},
"extentFreeList" : {
"num" : 0,
"totalSize" : 0
},
"ok" : 1
}
Am I doing it wrong and what do I have to do, to get the statistics like db.stats()?
I'm using php 7.1 with the composer package mongodb/mongodb. The MongoDB has version 2.6.10.
The second problem, then I execute $this->database->command(array('collStats' => "dev")); i get a RuntimeException "Collection [dev.dev] not found.". Why?
Found the reason for my RuntimeException... I requested "dev" as collectionname, but it's the name of the database.