mongoose不返回所有的领域

所以我有: UserSchema

var UserSchema = new mongoose.Schema({ firstName: String, lastName: String, image: { type: String, default: "http://via.placeholder.com/250x200" }, email: { type: String, required: [true, "Email missing."], unique: true }, kind: { type: String, enum: ["Admin", "Teacher", "Student"], default: "Student" }, isAdmin: { type: Boolean, default: false }, isPromote: { type: Boolean, default: false }, username: { type: String, required: [true, "Username missing."], unique: true }, password: String }, options); UserSchema.plugin(passportLocalMongoose); module.exports = mongoose.model("User", UserSchema); 

StudentSchema

 var options = {discriminatorKey: 'kind'}; var StudentSchema = new mongoose.Schema({ indexNumber: String, }, options); module.exports = User.discriminator("Student", StudentSchema); 

CourseSchema

 var CourseSchema = new mongoose.Schema({ code: { type: String, unique: true }, name: String, description: String, image: { type: String, default: "http://via.placeholder.com/250x200" }, data: [{ title: String, content: String }], teachers: [{ type: mongoose.Schema.Types.ObjectId, ref: "Teacher" }], students: [{ id: { type: mongoose.Schema.Types.ObjectId, ref: "Student" }, entryDate: { type: Date, default: Date.now } }] }); 

在我的数据库中,我有以下学生 (使用MongoDB指南针来显示): 2学生文件

另外,我有这个老师教师文件

而这个课程

课程文件

现在在课程展示页面,我想要招收学生和老师。 我走这样:

 Course.findById(req.params.id) .populate("students.id") .populate("teachers") .exec( function(err, foundCourse) {...} 

我只得到这个:

 students: [ { _id: 59dbd1259df328279cd5d588, entryDate: 2017-10-12T22:29:48.297Z }, { _id: 59dc07088c6fd636188d87c5, entryDate: 2017-10-12T22:29:48.297Z } ], teachers: [ { _id: 59dbc34832b0041b44a7f648, isPromote: false, isAdmin: false, kind: 'Teacher', image: 'http://via.placeholder.com/250x200' } ] 

注意这里:

  • 对于学生来说,我只能获得ref_ids,没有填充字段。
  • 对于教师,我没有得到一些领域,如名字,姓氏,用户名等(老师也是歧视用户)

我期望从填充查询中得到所有字段,例如,学生[0]应该看起来像这样:

 { _id: 59dbd1259df328279cd5d588, isPromote: false, isAdmin: false, kind: 'Student', image: 'http://via.placeholder.com/250x200', firstName: 'ss', lastName: 'ss', username: 'ss', entryDate: 2017-10-12T22:29:48.297Z } 

谁能告诉我如何获得这些领域,如何填充正确的方式?