python - Pymongo MongoClient: if you put a database in via URI, how do you get it back out? -
the documentation mongoclient
says 1 may 'host=' , give total mongodb uri. include database name. 1 time that, there way extract db name mongoclient object? i'm failing spot in source code.
i believe looking can found in pymongo.uri_parser
. in particular, @ parse_uri function. parse_uri
takes mongodb uri argument , returns dictionary containing values such username
, password
and, importantly, database
.
example:
from pymongo.uri_parser import parse_uri mongo_uri = 'mongodb://james:brewer@localhost/test' k, v in parse_uri(mongo_uri).items(): print k, ':', v
will print
username : james nodelist : [('localhost', 27017)] database : test connection : none password : brewer options : {}
hope helps!
python mongodb
No comments:
Post a Comment