how to issue a "show dbs" from pymongo

jacobra picture jacobra · Jun 22, 2012 · Viewed 32.9k times · Source

I'm using pymongo and I can't figure out how to execute the mongodb interactive shell equivalent of "show dbs".

Answer

jacobra picture jacobra · Jun 22, 2012
from pymongo import MongoClient
# Assuming youre running mongod on 'localhost' with port 27017
c = MongoClient('localhost',27017)
c.database_names()