我有一个带有数组的猫鼬模式lists
由对另一个集合的引用和嵌套的数字数组组成的对象:
var Schema, exports, mongoose, schema;
mongoose = require("mongoose");
Schema = mongoose.Schema;
schema = new Schema({
name: {
type: String,
required: true,
unique: true,
trim: true
},
lists: [{
list: {
type: Schema.ObjectId,
require: true,
ref: "List"
},
allocations: [{
type: Number,
required: true
}]
}],
createdAt: {
type: Date,
"default": Date.now
},
updatedAt: {
type: Date
}
});
exports = module.exports = mongoose.model("Portfolio", schema);
但是,我无法得到populate
按预期工作而无需获得TypeError: Cannot read property 'ref' of undefined
。我试过了populate('list')
and populate('lists list')
但我要么没有正确调用事物,要么我的架构没有正确形成。如果我简单地引用列表本身,我就不会遇到这个问题:
lists: [{
type: Schema.ObjectId,
require: true,
ref: "List"
}]
但我希望每个列表旁边都有分配数组。我需要做什么才能获得我想要的行为?