【发布时间】:2019-08-19 07:13:43
【问题描述】:
我正在为 MongoDB 中的用户创建一个模式,我在这里面临的问题是网络应用程序将是多语言的,所以这意味着我正在后端更具体地在用户模式中进行验证,所以需要字段和唯一性,如果出现问题,我会放置消息并将该消息显示给用户,因此如果用户使用不同语言的应用程序,是否可以从此处更改消息并显示给他。
这是我正在使用的架构:
const UserSchema = new Schema({
name: {
type: String,
trim: true,
required: "Name is required"
},
surname: {
type: String,
trim: true,
required: "Surname is required"
},
username: {
type: String,
trim: true,
unique: "Username already exist",
required: "Username is required"
},
email: {
type: String,
trim: true,
unique: "Email already exists",
match: [/.+\@.+\..+/, "Please fill a valid email address"],
required: "Email is required"
},
password: {
type: String,
required: "Password is required"
},
role: {
type: String,
trim: true,
required: "Role is required"
}
});
【问题讨论】:
标签: node.js mongodb express mongoose