Meteor Simple Schema - 当修饰符选项为真时,验证对象必须至少有一个操作符 [英] Meteor Simple Schema - When the modifier option is true, validation object must have at least one operator
问题描述
我不断收到错误消息:Exception while invoking method 'createUser' Error: 当修饰符选项为 true 时,验证对象必须至少有一个运算符
,当我尝试创建用户时.我正在使用meteor-simple-schema,但没有任何修复此错误的方法对我有用.我尝试使用 blackbox 和 optional 来查看问题出在哪里,但我一直收到相同的错误.
I keep getting the error: Exception while invoking method 'createUser' Error: When the modifier option is true, validation object must have at least one operator
when I try to create a user. I am using meteor-simple-schema, but none of the fixes with this error have worked for me. I have tried using blackbox and optional to see where the issue is but I keep getting the same error.
var Schemas = {};
Schemas.UserGamesPart = {
public: {
type: [String],
defaultValue: []
},
private: {
type: [String],
defaultValue: []
}
};
Schemas.UserGames = {
game1: {
type: Schemas.UserGamesPart
}
};
Schemas.UserProfile = new SimpleSchema({
games: {
type: Schemas.UserGames
}
});
Schemas.UpgradeDetails = new SimpleSchema({
subscribed_on: {
type: Date,
optional: true
},
stripe_charge_id: {
type: String,
optional: true
},
school_license: {
type: Boolean,
defaultValue: false,
optional: true
}
});
Schemas.UserProperties = new SimpleSchema({
paid: {
type: Boolean,
defaultValue: false
},
upgrade_details: {
type: Schemas.UpgradeDetails,
optional: true
}
});
Schemas.User = new SimpleSchema({
_id: {
type: String
},
username: {
type: String,
optional: true
},
emails: {
type: [Object]
},
"emails.$.address": {
type: String,
regEx: SimpleSchema.RegEx.Email,
optional: true
},
"emails.$.verified": {
type: Boolean,
optional: true
},
createdAt: {
type: Date
},
profile: {
type: Schemas.UserProfile,
blackbox: true,
optional: true
},
properties: {
type: Schemas.UserProperties,
blackbox: true,
optional: true
}
});
Meteor.users.attachSchema(Schemas.User);
我的accounts.create用户如下:
My accounts.creaate user is as follows:
Accounts.createUser({
email: $('#email').val(),
password: $('#password').val(),
profile: {
games: {
game1: {
public: [],
private: []
}
}
}
});
关于如何让它发挥作用的任何想法?
Any ideas on how I can get this to work?
推荐答案
您忘记在开头添加 new SimpleSchema
:
You forgot to add new SimpleSchema
there in the beginning:
Schemas.UserGamesPart = new SimpleSchema({
public: {
type: [String],
defaultValue: []
},
private: {
type: [String],
defaultValue: []
}
});
Schemas.UserGames = new SimpleSchema({
game1: {
type: Schemas.UserGamesPart
}
});
此外,我认为您对嵌套模式的使用有点偏离.仅在您需要重用架构时嵌套架构.为 UserGamesPart
创建一个单独的架构看起来很糟糕.试试这个:
Also I think your usage of the nested schemas is a little off. Only nest schemas when you need to reuse one. Creating a separate schema for UserGamesPart
looks horrible. Try this instead:
Schemas.UserGames = new SimpleSchema({
game1: {
type: Object
}
'game1.public': {
type: [String],
defaultValue: []
},
'game1.private': {
type: [String],
defaultValue: []
}
});
这更短也更容易阅读.
这篇关于Meteor Simple Schema - 当修饰符选项为真时,验证对象必须至少有一个操作符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!