我有两个集合,分别是通知和报告。每个通知都没有报告,并且通知具有通过报告中的同一字段从称为report_reference_id的字段报告的关系。
报表的一个字段称为“专家”,其中包含专家ID为“日期”的对象,在某些情况下没有日期,并且其值可能为空。
我需要获取包含特定专家报告的通知为null。
我试图通过此查询选择具有空值专家的报告
db.getcollection('generated_report').find({ $and[{'specialists.5cc022d222bca937f5263662':null},{'specialists.5cc022d222bca937f5263662':{$exists:true}} ] })
这将提供正确的报告文档。但要求是我需要具有这些特定报告的通知。应用程序是Laravel。这就是我对口才的尝试。
Notification::with(['report'=>function($q)use($authUserId){
$q->where('specialists.'.$specialistId,null)->where('specialists.'.$specialistId,'exists',true);
}])
->where('to',$authUser['_id'])
->where('action',$type)
->get()->toArray();
这将与报告一起发出通知,而与报告选择条件无关。非常感谢有人可以使用moloquest或查询生成器提供适当的解决方案。