How to make the right connection with mongo URI ?

11 views
Skip to first unread message

specter119

unread,
Apr 28, 2016, 7:39:57 AM4/28/16
to Mogo Python Object Wrapper

I don’t know how to connect mongodbs by URI correctly. 2 types of script list as followed, the type B can run .find() correctly, but the type A can’t. How to modify the codes in type A to work?

type A:

uri = "mongodb://{}:{}@{}:{}".format(username, password, host, port)
for k in ["A","B","C"]:
    exec "{}_uri = '{}/{}_{}'".format(k, uri, k, envname)
    exec "db_{} = MongoClient({}_uri)".format(k, k)

type B:

connection = MongoClient(host, port)
for k in ["A","B","C"]:
    exec "db_{} = connection.{}_{}".format(k, k, envname)
    exec "db_{}.authenticate(username, password)".format(k)
Reply all
Reply to author
Forward
0 new messages