I'm working in Nest.js using Mongoose. While creating schema, I have a field extra_options which can store any type of value (array, object, string etc). Keeping its type as "any" does not work. What should be the correct type? Here is a fragment of the code.
@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;
}
I'm working in Nest.js using Mongoose. While creating schema, I have a field extra_options which can store any type of value (array, object, string etc). Keeping its type as "any" does not work. What should be the correct type? Here is a fragment of the code.
@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;
}
Share
Improve this question
asked Jan 6, 2021 at 13:50
Akanksha SharmaAkanksha Sharma
2092 silver badges6 bronze badges
1 Answer
Reset to default 15import * as mongoose from 'mongoose';
@Prop({type: mongoose.Schema.Types.Mixed})
extra_options: any;
This worked.