简体   繁体   English

MongoDB 中的聚合连接不返回结果

[英]Aggregate Join in MongoDB not returning results

I am trying to do an aggregate join to find patient information in the 'patients' table based on 'patient_id' field in the bookings table.我正在尝试进行聚合连接,以根据预订表中的“患者 ID”字段在“患者”表中查找患者信息。 Aggregate join is not returning results even though there are matching records in the 'patients' table.即使“患者”表中有匹配的记录,聚合连接也不会返回结果。 Am I doing something wrong?难道我做错了什么? 在此处输入图像描述

If the _id field in the "patients" collection is an ObjectId, it won't match when you compare to the string value stored in patient_id .如果“患者”集合中的_id字段是 ObjectId,当您与存储在patient_id中的字符串值进行比较时,它将不匹配。 You can use the $addFields aggregation step to add a new field to the documents with the "patient_id" field cast to an ObjectId, but I'd advise you to instead store reference id's as ObjectIds您可以使用$addFields聚合步骤将新字段添加到文档中,并将“患者 ID”字段转换为 ObjectId,但我建议您将参考 ID 存储为 ObjectIds

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM