我在使用 Mongoose 的 Nest.js 中工作。在创建模式时,我有一个字段 extra_options 可以存储任何类型的值(数组、对象、字符串等)。将其类型保持为“any”是行不通的。正确的类型应该是什么?这是代码片段。
@Schema({
collection: 'xyz',
timestamps: {
updatedAt: 'updated_at',
createdAt: 'created_at'
},
})
export class xyz {
@Prop({default: true})
active: boolean;
@Prop()
extra_options: any;
@Prop({required: true})
created_by: string;
}
最佳答案
import * as mongoose from 'mongoose';
@Prop({type: mongoose.Schema.Types.Mixed})
extra_options: any;
这有效。
关于javascript - 如果 "any"不能在 Nest.js 中使用,模式中的字段类型应该是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65597011/