简体   繁体   English

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

[英]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.

相关问题 在 MongoDB 中,使用 Java 我如何查询以在数据库或集合中查找超过 15 MB 存储大小的文档 - In MongoDB, using Java how can I query to find documents exceeding 15 MB storage size in a database or collection 如何在MongoDB中找到类似的文档? - How can I find similar documents in MongoDB? 如何在MongoDB中搜索集合以在其文档之一中找到嵌套值 - How can I search a collection to find a nested value in one of its documents in MongoDB MongoDB - 如何找到其他集合中未被文档引用的所有文档 - MongoDB - how can I find all documents that aren't referenced by a document from another collection 如何使用@Query注释在mongodb中查找所有文档(在集合中) - How do I find all documents (in a collection) in mongodb using the @Query annotation 如何在一个集合中找到另一个集合中的文档未引用的 MongoDB 文档? - How to find MongoDB documents in one collection not referenced by documents in another collection? MongoDB-如何为上限集合设置文档限制? - MongoDB - how can i set a documents limit to my capped collection? 如何聚合数组中的文档而不是 MongoDB 中的集合? - How can I aggregate the documents in an array instead of in a collection in MongoDB? 如何在MongoDB集合中将以下JSON作为不同的文档插入 - How can I insert following JSON in MongoDB collection as different documents 如何使用 Node.js 返回 MongoDB 集合中的文档数? - How can I return the number of documents in a MongoDB collection using Node.js?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM