Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在一个集合中有文档,这些文档具有一组属性(1-400 个不同的数值)。
现在我想获取具有这些属性之一的另一个集合的所有文档(这些文档只有一个属性)。
我怎么能做到这一点,最好是一次通话?
由于 MongoDB 不是关系 DBMS,因此仅通过一次调用是不可能实现的。 您需要做的是首先检索要用于搜索的文档。检索到它后,您将使用存储在文档中的该数组$in对其他集合的字段进行查询。所以对于 mongo shell,这可能是这样的:
$in
var ar = db.coll1.findOne().numArray db.coll2.find({b: { $in : ar }})