填充Mongoose子文档

时间:2018-04-06 22:07:38

标签: mongoose-schema mongoose-populate

我有一个关于猫鼬模式的问题:

`var ProjectSchema = new mongoose.Schema({
    name: String,
    resources: [{
        employee: {type: Schema.Types.ObjectId, ref: 'Employee'},
        dailyRate: Number
    }],`...

我尝试填充resources.employee字段没有成功...已尝试过:

  • .populate('resources.employee')
  • .populate('resources.employee', model: 'Employee'})
  • 等...

任何建议?

提前致谢

1 个答案:

答案 0 :(得分:0)

没关系,只是我的插件无效......

正确的语法是:

.populate({path:'resources.employee', model:'Employee'})