我的数据库中有一个字段example
,我希望它是Number
或String
:
export const mySch = new mongoose.Schema({
example: {
type: String,
},
});
我该怎么做?
mongooseSchema.Types.Mixed
中有一个类型,可以用来保存给定字段中任何类型的值。然而,我还没有找到一种方法来将其限制为一个特定的类型子集,例如String和Number。
如果你想自己详细学习,下面是链接:https://mongoosejs.com/docs/schematypes.html#mixed.
您可以使用Mongoose鉴别器。
https://mongoosejs.com/docs/discriminators.html