【发布时间】:2019-01-08 10:57:18
【问题描述】:
我有以下架构:
引用 CostCenter 子文档能力中的能力的事件。
const OccurrenceSchema = new mongoose.Schema({
date: {
type: Date,
default: Date.now,
},
competence: {
type: mongoose.Schema.Types.ObjectId,
ref: 'CostCenter.competences',
},
...
})
CostCenter,我有一个子文档数组,可以通过 Occurence 引用。
const CostCenterSchema = new mongoose.Schema({
name: {
type: String,
required: true,
trim: true,
},
competences: [CompetenceSchema],
});
最后是能力。
const CompetenceSchema = new mongoose.Schema({
name: {
type: String,
required: true,
trim: true,
},
});
当我尝试填充权限时,我得到“架构尚未注册模型 \"CostCenter.competences\"。\n使用 mongoose.model(name, schema)”。
const occurrence_list = (request, response) => {
Occurrence.find()
.populate('occurrence origin tag entity method priority competence')
.then(occurrences => response.send(occurrences))
.catch(e => response.send(e));
};
在引用子文档时如何填充事件?
【问题讨论】:
标签: node.js mongodb express mongoose