1
假設我有兩個模式:
1. UserEnrolledCourses貓鼬查詢
var userCoursesSchema = new mongoose.Schema({
user: { type: mongoose.Schema.Types.ObjectId, ref: 'users'},
courseId: { type: mongoose.Schema.Types.ObjectId, ref: 'courses'},
isEnrolled: Boolean,
});
2. CourseResources
var resourcesSchema = new mongoose.Schema({
courseId: { type: mongoose.Schema.Types.ObjectId, ref: 'courses', required: true },
type: {type:String, required:true},
});
兩者都從courses
共享相同的參考courseId
架構。
所以,我的目標是從查詢生成結果,對於每個courseId一個用戶註冊,列出所有可用的資源。那可能嗎?