2

I have an Exercise model in Mongoose that has a sets field, which holds information about each set- such as reps, weight, etc.

const repExerciseSchema = new mongoose.Schema({
    // ...other fields
    sets: [Set],
});

const Set = new mongoose.Schema({
    reps: {
       type: Number,
        required: true,
        min: 0
    },
    weight: {
        type: Number,
        required: true,
        min: 0
    },
    //... other fields
});

However, I would like to have different kinds of sets, such as a dropset or superset. Is there any way to use enums with sub schemas, such as

sets: {
    type: mongoose.Types.Any, // I don't know if this exists
    enum: [Dropset, Superset, Set], //enum for schemas
    required: true
}

If not, is there any other way to accomplish this? I thought of having Set as generic as possible with String fields and use JSON.stringify, but it would be a hassle to have to stringify and parse each set when querying or updating. Any help would be appreciated!

Roy Z
  • 117
  • 1
  • 7
  • 1
    Hi Roy, I think this might help you: https://stackoverflow.com/questions/35468855/multiple-schema-references-in-single-schema-array-mongoose – Nandun Bandara Oct 20 '20 at 12:43

0 Answers0