TypeError:无法使用“in”运算符在 true 中搜索“transform”

问题描述 投票:0回答:0

我有一个模型创建如下

const KPISchema = new Schema({
    totalProfit: {
        type: mongoose.Types.Currency,
        currency: "USD",
        get: (v) => v / 100
    },
    totalRevenue: {
        type: mongoose.Types.Currency,
        currency: "USD",
        get: (v) => v / 100
    },
    totalExpenses: {
        type: mongoose.Types.Currency,
        currency: "USD",
        get: (v) => v / 100
    },
    expensesByCategory: {
        type: Map,
        of: {
            type: mongoose.Types.Currency,
            currency: "USD",
            get: (v) => v / 100
        }
    },
    monthlyData: [monthSchema],
    dailyData: [daySchema],
}, { timestamps: true, toJSON: true });

// 这是错误的

{ timestamps: true, toJSON: true });

// 我再次解决这个问题

{ timestamps: true, toJSON: { getters: true }});

const KPISchema = new Schema({
    totalProfit: {
        type: mongoose.Types.Currency,
        currency: "USD",
        get: (v) => v / 100
    },
    totalRevenue: {
        type: mongoose.Types.Currency,
        currency: "USD",
        get: (v) => v / 100
    },
    totalExpenses: {
        type: mongoose.Types.Currency,
        currency: "USD",
        get: (v) => v / 100
    },
    expensesByCategory: {
        type: Map,
        of: {
            type: mongoose.Types.Currency,
            currency: "USD",
            get: (v) => v / 100
        }
    },
    monthlyData: [monthSchema],
    dailyData: [daySchema],
}, { timestamps: true, toJSON: { getters: true }});
javascript node.js mongodb mongoose mongoose-schema
© www.soinside.com 2019 - 2024. All rights reserved.