需求说明
实现类似关系数据库的select in subquery,如下:
SELECT * FROM table1 WHERE some_id NOT IN ( SELECT id FROM table2 WHERE some_field = 'some_value' )
实现
db.collect_name1.find( { "some_id": { $nin: db.collection_name2.find({}, { "some_field": "some_value" }).toArray().map(e => e.pid) } } )
mongodb的$nin相当于not in $in就相当于关系型数据库的in
文章评论