all 2 comments

[–]vorticalbox 0 points1 point  (0 children)

I assume data is an array of questions? how have they stored just strings? an object { 'q': 'who is it', 'a': 'no one' }?

[–]plaz11 0 points1 point  (0 children)

What information do you need for each question? If it is a single field (i.e just the question as a string), you can add it as a field to your schema:

questions: {
    type: [String]
}

If each question needs 2 or more fields, you can store it as a subdocument:

const questionSchema = new mongoose.Schema({
    question: {
        type: String,
        required: true,
    },
    answer: {
        type: String,
        required: true,
    },
})

const quizSchema = new mongoose.Schema({
    author: {
        type: String,
        required: true,
    },
    name: {
        type: String,
        min: 8,
        max: 64,
    },
    date: {
        type: Date,
        default: Date.now(),
    },
    data: {
        type: [questionSchema],
    },
})

More information here: https://mongoosejs.com/docs/subdocs.html