Mongodb 通过mongoose架构中的函数返回mongoose类型

Mongodb 通过mongoose架构中的函数返回mongoose类型,mongodb,validation,mongoose,Mongodb,Validation,Mongoose,关于上述模式,是否有一种方法可以使用基于另一个属性的函数返回属性的类型?我可以对除“type”之外的其他属性执行此操作。在user属性中,我在“type”中有一个函数,我希望返回该类型,但我不断收到以下错误: new mongoose.Schema({ status:{ type:String, enum:['General','Private'] } user: { type:function() {return this.status == 'Private' ? mongoose.Sche

关于上述模式,是否有一种方法可以使用基于另一个属性的函数返回属性的类型?我可以对除“type”之外的其他属性执行此操作。在user属性中,我在“type”中有一个函数,我希望返回该类型,但我不断收到以下错误:

new mongoose.Schema({
status:{
type:String,
enum:['General','Private']
}
user: {
type:function() {return this.status == 'Private' ? mongoose.Schema.Types.ObjectId : [] }
}
})
[0]     throw new TypeError(`Invalid schema configuration: \`${name}\` is not ` +
[0]     ^
[0]
[0] TypeError: Invalid schema configuration: `Type` is not a valid type at path `user`. See xxxxxxx for a list of valid schema types.