我有以下集合,它有一个使用Collection2 Meteor 包address
定义的嵌套对象。我无法插入此嵌套对象的数据...
样本数据
var addresses = [{
"venue": "Kirkstall Abbey",
"street": "Kirkstall Lane",
"city": "Leeds",
"county": "West Yorkshire",
"postcode": "LS6 3LF"
},{
"venue": "Headingley High School",
"street": "",
"city": "Leeds",
"county": "West Yorkshire",
"postcode": "LS6 7QR"
}];
var locations = [{
"name": "Kirkstall Abbey",
"address": addresses[0],
"image": null,
"active": true
},{
"name": "Headingley",
"address": addresses[1],
"image": null,
"active": true
}];
集合定义
ClassLocation = new Mongo.Collection("class-location");
Schemas.ClassLocation = new SimpleSchema({
name: {
type: String,
optional: true
},
address: {
type: Object
},
image: {
type: String,
optional: true
}
active: {
type: Boolean,
optional: true
}
});
ClassLocation.attachSchema(Schemas.ClassLocation);
常规
if(ClassLocation.find().count() === 0) {
_.each(locations, function (location) {
console.log(location.address);
ClassLocation.insert(location);
});
}
问题
控制台很好地注销了位置地址详细信息对象,但是我的插入文档的 MongoDb 集合对于地址是空的?我尝试了很多事情,包括在初始插入后进行更新(这远非理想)。
谁能解释为什么没有插入这个嵌套对象以及修复它需要什么?
谢谢