[英]Embedded Schema Inserting Blank in Meteor using Collection2
我对流星还很陌生,并尝试使用使用嵌入式架构的模型将其插入到集合中。 嵌入式模式中的内容未插入数据库中,而是一个空条目。
主要模型被附加到集合中。
Guests = new Mongo.Collection('guests');
Schema = {}
Guests.attachSchema(new SimpleSchema({
BasicInformation : {
type: Schema.basicInfo,
optional: false,
},
})
basicInfo模式定义如下。
Schema.basicInfo = new SimpleSchema({
firstName: {
type: String,
},
middleName: {
type: String,
},
lastName: {
type: String,
}
})
我用它来插入一个普通的js文件中的集合。
Guests.insert({
BasicInformation: {
firstName: 'First Name',
middleName: 'Middle Name',
lastName: 'Last Name'
},
})
如果删除架构并在主模型中添加字段而不是使用嵌入式架构,则确实会插入它。 不知道怎么回事...帮助!
欢迎使用堆栈溢出。 而且,正如@Jankapunkt所说,请将您的代码作为格式化的块放入您的问题中。 如果删除图片,则指向其他位置托管的图片的链接可能无法正常工作。 对于我们来说,更容易修复您的代码并向您展示其外观。
我认为在设置架构时,架构对象为空。 您稍后可以向其中添加信息,但那时为时已晚。 如果您在问题中输入代码,我可以向您展示如何操作,但是我不愿意为您重新输入代码。
更新:很好。 在将Schema对象附加到表之前,需要填充它:
Guests = new Mongo.Collection('guests');
Schema = {} // Right now the object is empty
Schema.basicInfo = new SimpleSchema({ // So we add the sub-schema
firstName: {
type: String,
},
middleName: {
type: String,
},
lastName: {
type: String,
}
})
Guests.attachSchema(new SimpleSchema({
BasicInformation : {
type: Schema.basicInfo, // previously this was undef, now it is correct
optional: false,
},
})
那应该为您工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.