Mongodb: How To Get Db.stats() From Api
Solution 1:
The Javascript shell's stats
command helper actually invokes a command named dbstats
, which you can run from PyMongo using the Database.command
method. The easiest way to find out what command a shell helper will run is to invoke the shell helper without parentheses -- this will print out the Javascript code it runs:
> db.statsfunction (scale) {
returnthis.runCommand({dbstats:1, scale:scale});
}
As for why some commands have helpers and others do not, it's largely a question of preference, time, and perceived frequency of use by the driver authors. You can run any command by name with Database.command
, which is just a convenience wrapper around db.$cmd.find_one
. You can find a full list of commands at List of Database Commands. You can also submit a patch against PyMongo to add a helper method for commands you find that you need to invoke frequently but aren't supported by PyMongo yet.
Post a Comment for "Mongodb: How To Get Db.stats() From Api"