var userSchema = Schema({
email: {
type: String,
unique: true,
match: /^[a-z0-9._-]+@[a-z0-9.-]+\.[a-z]{2,4}$/,
lowercase: true,
trim: true
},
nickname: {
type: String,
trim: true,
required: true
},
password: { type: String, required: true },
url: { type: String, trim: true, default: '' },
role: {
type: String,
enum: [ 'admin', 'reader' ],
default: 'reader'
},
about: { type: String, trim: true },
created: { type: Date, default: Date.now, required: true }
});
我想用更用户友好的东西来定制它,但我不知道如何为所需的唯一索引和枚举失败设置自定义错误消息。我能怎么做?