嵌入式模式使用 Collection2 在 Meteor 中插入空白
Embedded Schema Inserting Blank in Meteor using Collection2
我对 meteor 还很陌生,并尝试使用使用嵌入式模式的模型插入到集合中。嵌入式模式中的内容没有被插入到数据库中,而是一个空条目。
正在将主模型附加到集合中。
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'
},
})
如果我删除架构并在主模型中添加字段而不是使用嵌入式架构,那么它会被插入。不知道怎么回事……求助!
欢迎来到 Stack Overflow。而且,正如@Jankapunkt 所说,请将您的代码作为格式化块放在您的问题中。如果图像被删除,指向其他地方托管的图片的链接可能无法使用。我们也更容易修复您的代码并向您展示它应该是什么样子。
我认为在您设置模式时,模式对象是空的。您稍后向其中添加信息,但那时为时已晚。如果你把代码放在你的问题中,我可以告诉你怎么做,但我不愿意为你重新输入。
更新:
干得好。在将架构对象 附加到 table:
之前,您需要填充架构对象
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,
},
})
这应该适合你。
我对 meteor 还很陌生,并尝试使用使用嵌入式模式的模型插入到集合中。嵌入式模式中的内容没有被插入到数据库中,而是一个空条目。
正在将主模型附加到集合中。
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'
},
})
如果我删除架构并在主模型中添加字段而不是使用嵌入式架构,那么它会被插入。不知道怎么回事……求助!
欢迎来到 Stack Overflow。而且,正如@Jankapunkt 所说,请将您的代码作为格式化块放在您的问题中。如果图像被删除,指向其他地方托管的图片的链接可能无法使用。我们也更容易修复您的代码并向您展示它应该是什么样子。
我认为在您设置模式时,模式对象是空的。您稍后向其中添加信息,但那时为时已晚。如果你把代码放在你的问题中,我可以告诉你怎么做,但我不愿意为你重新输入。
更新: 干得好。在将架构对象 附加到 table:
之前,您需要填充架构对象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,
},
})
这应该适合你。