我有一个document
调用Mapping
,它有一个_id
和一个叫Mappings的对象数组。 我有另一个collection
叫NewMappings
。对于NewMappings
中的每个_id
,我需要在Mappings (of Mapping collection)
的数组内搜索并返回Mapping
的_id
。基于另一个搜索MongoDB集合
我写了这样的东西,但它没有返回任何东西。
var d=db.NewMappings.find();
d.forEach(function(item){
db.matching.find({Mappings: {$elemMatch : {TargetId: item._id}}})
})
然而,该查询返回的值
var d=db.NewMappings.find();
db.matching.find({Mappings: {$elemMatch : {TargetId: d[0]._id}}})
我缺少的东西? 请帮帮我。我在黑暗中。提前致谢。
在您使用的forEach,你正在创建一个不返回值的函数的代码。您需要存储或打印它。 –
你可以添加一段代码来显示吗?谢谢。 – user3245595