I am writing an app with Mongoose where I have different types of questions and an exam which contains questions. I am new to this and the code I try to write below might be completely wrong, so let me first explain what is my purpose: when I edit a question, I want it to be changed in the exam it exists too without rewriting all of the exam questions array. I don't know if just storing the question ids would be efficient (is it?). This is what the current code looks like:
const OneChoiceQuestionSchema = new Schema({
// a lot of stuff
}, {timestamps: true});
const MultipleChoiceQuestionSchema = new Schema({
// more stuff
}, {timestamps: true});
const ExamSchema = new Schema({
// exam stuff
questions: [], // this will contain of the schemas declared aboce
}, {timestamps: true});
I have tried adding a question to an exam and then editing that question. Obviously, the exam question did not change since they have no references. I have thought of creating another schema called QuestionSchema
which will contain question: { type: Mixed }
, but I don't that if that is the correct way to do it. Any help is appreciated!