Typegoose: Unable to find valid prop mapping for array of arbitrary objects

Created on 1 Jul 2020  路  2Comments  路  Source: typegoose/typegoose

I am trying to migrate this schema to Typegoose:

new mongoose.Schema({
    quests: [{
        team: {
            type: [String],
            default: [],
        },
        passed: Boolean,
    }]
})

Based on the documentation and looking at many issues on here, it would seem that this is at least close to the needed Typegoose version:

class Whatever {
    @prop({
        items: {
            team: [String],
            passed: Boolean,
        }
    })
    quests!: {
        team: string[],
        passed?: boolean,
    }[];
}

This is resulting in Error: "Whatever.quests"'s Type is invalid! Type is: "[object Object]"

I think I could get around this by promoting the items to their own Typegoose class. In my original schema I didn't do this because I didn't need any subdocument functionality on these items. Change tracking, IDs, etc... it all comes at a cost.

So am I doing this wrong? Is this a bug? Or simply unsupported schema?

Versions

  • typegoose: 7.2.0
  • mongoose: 5.9.20
question

All 2 comments

typegoose currently (and probably for the near-future) does not support objects, with typegoose such things need to be an different class

if you worry about all having an _id, then you can disable that either on the classes themself (with modelOptions) or as an prop-option

  • @modelOptions({ schemaOptions: { _id: false } })
  • @prop({ _id: false })

closing because this question seems to be answered

Was this page helpful?
0 / 5 - 0 ratings