【发布时间】:2014-12-13 19:42:43
【问题描述】:
我有一个Student collection和一个Class collection,class collection有一个studentRefs,是一个学生列表 ids,但学生没有引用 班级 id 的属性。
现在,我有另一个学生 ID 列表,我想获取他们的课程。我想知道如何查询 mongoose 或 mongoDB 中的类。 mongoose 中的架构如下所示。
classSchema = Schema({
className: String,
studentRefs: [{type: Schema.Types.ObjectId, ref: 'students'}]
});
studentSchema = Schema({
studentName: String
});
例如,
学生A 和B 在Class1,
学生C 和D 在Class2,
学生E 和F 在Class3。
现在,我有一个[A, B, C]。
我想获取该数组中学生的班级。
所以,我的预期结果是[Class1, Class2]。
【问题讨论】: