如何使用变量作为集合在 MongoDB 中查找文档?

How can I find documents in MongoDB using a variable as collection?

我想使用以下命令:

coll = sys.argv[1]
docs = db.coll.find()

那是行不通的。如果我像这样硬编码它,它就可以工作:

docs = db.collection_I_want_to_query.find()

我猜 find 函数不起作用,因为 coll 是一个字符串。但是有没有可能使用变量来查询?

http://api.mongodb.org/python/current/tutorial.html#getting-a-database

col = sys.argv[1]
db[col].find()