Meteor 组合简单模式错误
我正在尝试使用简单模式组合字段。它适用于Meteor 组合简单模式错误,meteor,simple-schema,Meteor,Simple Schema,我正在尝试使用简单模式组合字段。它适用于Schema.UserProfile,但不适用于Schema.accountStatus 如果在创建新帐户时尝试填充该字段,则会出现错误。想一想为什么,真的会有帮助吗,谢谢 路径:schemas.js Schema = {}; Schema.accountStatus = new SimpleSchema({ isUserAccountActive: { type: Boolean, optional: true
Schema.UserProfile
,但不适用于Schema.accountStatus
如果在创建新帐户时尝试填充该字段,则会出现错误。想一想为什么,真的会有帮助吗,谢谢
路径:schemas.js
Schema = {};
Schema.accountStatus = new SimpleSchema({
isUserAccountActive: {
type: Boolean,
optional: true
},
startDate: {
type: Date,
optional: true
},
endDate: {
type: Date,
optional: true
}
});
Schema.UserProfile = new SimpleSchema({
firstName: {
type: String,
optional: false
},
lastName: {
type: String,
optional: true
},
});
Schema.User = new SimpleSchema({
profile: {
type: Schema.UserProfile,
optional: true
},
// Make sure this services field is in your schema if you're using any of the accounts packages
services: {
type: Object,
optional: true,
blackbox: true
},
accountStatus: {
type: Schema.accountStatus,
optional: true
},
// In order to avoid an 'Exception in setInterval callback' from Meteor
heartbeat: {
type: Date,
optional: true
}
});
Meteor.users.attachSchema(Schema.User);
Meteor.startup(function () {
console.log('Running server startup code...');
Accounts.onCreateUser(function (options, user) {
if (options.profile && options.profile.roles) {
//include the user profile
Roles.setRolesOnUserObj(user, options.profile.roles);
}
if (options.profile) {
// include the user profile
user.profile = options.profile;
}
// other user object changes...
// ...
user.isUserAccountActive = false;
return user;
});
});
路径:startup.js
Schema = {};
Schema.accountStatus = new SimpleSchema({
isUserAccountActive: {
type: Boolean,
optional: true
},
startDate: {
type: Date,
optional: true
},
endDate: {
type: Date,
optional: true
}
});
Schema.UserProfile = new SimpleSchema({
firstName: {
type: String,
optional: false
},
lastName: {
type: String,
optional: true
},
});
Schema.User = new SimpleSchema({
profile: {
type: Schema.UserProfile,
optional: true
},
// Make sure this services field is in your schema if you're using any of the accounts packages
services: {
type: Object,
optional: true,
blackbox: true
},
accountStatus: {
type: Schema.accountStatus,
optional: true
},
// In order to avoid an 'Exception in setInterval callback' from Meteor
heartbeat: {
type: Date,
optional: true
}
});
Meteor.users.attachSchema(Schema.User);
Meteor.startup(function () {
console.log('Running server startup code...');
Accounts.onCreateUser(function (options, user) {
if (options.profile && options.profile.roles) {
//include the user profile
Roles.setRolesOnUserObj(user, options.profile.roles);
}
if (options.profile) {
// include the user profile
user.profile = options.profile;
}
// other user object changes...
// ...
user.isUserAccountActive = false;
return user;
});
});
我现在明白了:
isUserAccountActive
是accountStatus
的子键。更改:
user.isUserAccountActive = false;
到
不清楚为什么会产生服务器错误,可能是因为您在服务器端执行此更新。错误消息是什么,插入的对象是什么样子?错误消息是“内部服务器错误”。我正在尝试将'user.isUserAccountActive=false'插入数据库。我已经删除了样板代码。我是否正确地组合了模式?不,这不起作用。我仍然收到服务器错误。在我的控制台中,我收到了以下错误:“调用方法“ATCreateUserServer”时发生异常错误:无法设置未定义的I20160204-19:35:42.568(11)的属性“isUserAccountActive”?在AccountsServer.onCreateUserHook(server/startup.js:18:43)上,这样的传奇!谢谢