私信  •  关注

jelongpark

jelongpark 最近回复了
7 年前
回复了 jelongpark 创建的主题 » MongoDB如何筛选在其他集合中找到的记录

Neil Lunn的解决方案有效,但我有另一种方法,因为 $lookup pipe不支持“from”语句中的shard集合。

所以我以前使用的是简单的Java脚本。它简单且易于修改。但对于性能,您应该有适当的索引!

var mycursor = db.collA.find( {}, {_id: 0, myId:1} ) 

mycursor.forEach( function (x){ 
    var out = db.collB.count( { yourId : x.myId } )
    if ( out > 0) {
        print('The id exists! ' + x.myId); //debugging only

        //put your other query in  here....

        }
} )