在新文件中定义角色数组, 在定义新架构时将该角色模块用作架构类型
//define this role array
exports.module = {
role:['admin','consumer','super_admin']
};
//can we use the above role array as a schema type when defining schema
var UserSchema = new mongoose.Schema({
name: {
type:String,
required:true
},
profilePic:String,
email:{
type:String,
unique: true,
lowercase: true,
required:true
},
role:{
type: [userRole.module.role],
required:true
}
});
答案 0 :(得分:0)
您可以在
找到答案答案 1 :(得分:0)
要创建新的模式类型,您需要从mongoose.SchemaType继承并将相应的属性添加到mongoose。要创建自定义架构类型,请点击以下链接:
答案 2 :(得分:0)
来自猫鼬文档:
const ToySchema = new Schema({ name: String });
const ToyBoxSchema = new Schema({
toys: [ToySchema], // <== used here
buffers: [Buffer],
strings: [String],
numbers: [Number]
// ... etc
});