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)