我的猫鼬模型中有模式类型 Map 。在这张地图中,每个元素都引用了另一个模型。我知道可以在数组中填充属性,但是 Map 类型呢?因为像“map_type_attribute.some_attribute_to_populate”这样的嵌套不起作用。:)
这是我的模型:
const Mongoose = require('mongoose');
const parameter = Mongoose.Schema({
definition: {
type: Mongoose.Schema.Types.ObjectId,
ref: 'Definition',
},
value: {},
}, {_id: false});
const schema = Mongoose.Schema({
model: {
type: Mongoose.Schema.Types.ObjectId,
ref: 'Model'
},
name: String,
objectid: Number,
externalId: String,
properties: Mongoose.Schema.Types.Mixed,
parameters: {
type: Map,
of: parameter
}
});
module.exports = Mongoose.model('Element', schema);
这就是我试图填充定义字段的方式:
const request = Element.find(query, projection);
request.populate('parameters.definition');
request.exec( (err, docs) => {
...