What is the BSON doc (query) for the cmd `show dbs` in MongoDB? -
according getting started mongodb, can use show dbs
list of existing databases.
but kind of command running in mongo shell
.
my question how write mongodb query (bson)
list of databases, , query should sent to?
it's not query, can run listdatabases
command against admin database list of databases in bson:
> use admin switched db admin > db.runcommand({listdatabases : 1}) { "databases" : [ { "name" : "local", "sizeondisk" : 83886080, "empty" : false }, ], "totalsize" : 83886080, "ok" : 1 }
most programming language engines mongodb can run commands in addition queries given right syntax. example, in java:
db db = mongo.getdb("admin"); dbobject cmd = new basicdbobject("listdatabases", 1); commandresult result = db.command(cmd);
interestingly, if you're insistent on being query, can query virtual collection $cmd
on admin
database run commands submitting queries:
> use admin switched db admin > db.$cmd.findone({"listdatabases":1})
Comments
Post a Comment