我不确定如何填充下面的示例模式,或者是否可能。引用可以在如下对象中吗?如果可以,您将如何填充它?例如.populate('map_data.location');
?
var sampleSchema = new Schema({
name: String,
map_data: [{
location: {type: Schema.Types.ObjectId, ref: 'location'},
count: Number
}]
});
或者我是否必须有两个单独的数组用于位置和计数,如下所示:
// Locations and counts should act as one object. They should
// Be synced together perfectly. E.g. locations[i] correlates to counts[i]
locations: [{ type: Schema.Types.ObjectId, ref: 'location'}],
counts: [Number]
我觉得第一个解决方案是最好的,但我不完全确定如何让它在 Mongoose 中工作。
非常感谢您的帮助!