[英]How can I find documents in MongoDB using a variable as collection?
I want to use the following commands: 我想使用以下命令:
coll = sys.argv[1]
docs = db.coll.find()
That does not work. 那行不通。 If I hardcode it like this it works: 如果我这样进行硬编码,它将起作用:
docs = db.collection_I_want_to_query.find()
I guess the find-function does not work because coll is a string. 我猜find函数不起作用,因为coll是一个字符串。 But is there a possibility to use variables for querying? 但是有可能使用变量进行查询吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.