假设我有两个类似的模型类:
class Institution(Model):
name = StringField()
class Student(Model):
full_name = StringField()
institution = ReferenceField(Institution)
是否可以在汇总管道中访问Student.institution.name
?
答案 0 :(得分:2)
来自monogdb版本3.2 这可以通过$lookup实现,但有一些限制(例如,不适用于分片集合),例如:
db.student.aggregate([
{
$lookup:
{
from: "institution",
localField: "institution",
foreignField: "_id",
as: "institution"
}
}
])