I am using pymongo to connect to my mongodb database. I am trying to call the database name and collection name in the connection string but I can't figure it out.
If I have a database name (mydb) and a collection named (mycol) this example works:
con = Connection('mymongodbhost')
d = con.mydb.mycol.find_one()
print (d)
That works fine but lets say I am defining mydb and mycol as variables, how do I call them in the connection string. So lets say I have:
db = parser.get('some_conf_file', 'db_name')
col = parser.get('some_conf_file', 'col_name')
How do I specify the db and col variables (which work that is just a code snippit) in my connection string? I've tried all sorts of combinations, and this certainly doesn't work:
d = con.db.col.find_one()
print (d)
This basically is calling the db (db) and the collection (col). But I want the variable values replaced by db and col in the example above.
Thanks.