我不确定如何填充下面的示例模式或甚至是否可能.引用可以在下面的对象中吗?如果可以的话,你会如何填充它?比如.populate('map_data.location');?
var sampleSchema = new Schema({
name: String,
map_data: [{
location: {type: Schema.Types.ObjectId, ref: 'location'},
count: Number
}]
});
Run Code Online (Sandbox Code Playgroud)
或者我必须有两个单独的数组用于位置和计数,如下所示:
// 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]
Run Code Online (Sandbox Code Playgroud)
我觉得第一个解决方案是最好的,但我不完全确定如何让它在Mongoose中运行.
非常感谢您的帮助!