最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What should be the type of a field in schema if "any" cannot be used in Nest.js? - Stack Overflow

programmeradmin2浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 15
import * as mongoose from 'mongoose';

@Prop({type: mongoose.Schema.Types.Mixed})
extra_options: any;

This worked.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论