mongo查询指定字段,其中查询条件为空

1.mongo查询指定字段,其中查询条件为空

db.test.find({},{projectId:1, envId:1 ,subjectNo:1})

2.如何实现两表的内连接查询
** 暂未找到合适的方法 **
本人解决方案:
在sql中的方式类似:
select b.subject_id, b.environmentId from db.test a inner join subject_form_statistic1 b where a.projectId=b.study_id and a.envId=b.environmentId and a.subjetNo=b.subject_subject_no
1.使用db.test.find({},{projectId:1, envId:1 ,subjectNo:1})查出projectId,envId,subjectNo字段,暂存map
2.遍历map,拼接or、and

db.getCollection('subject_form_statistic1').
    find({$or:
           [
            {$and:[{"study_id":'8a81c08b6c19a1ab016c6b49455a54ef'},{"environmentId":'9cddc3aec3444e5db22dd5937f61999a'},{"subject_subject_no":'91'}]}
           ]
         },{ subject_id: 1, environmentId: 1 }).limit(1)

猜你喜欢

转载自blog.csdn.net/kunAUGUST/article/details/118419812