Reputation: 159
I have a test model which can have questions with one(radio) and multiple(checkbox) answers. Questions store in array. How can I store them without turning off validation(they represented by different subdocs)? Is it good idea to create one subdoc with its type inside and operate with doc depending on that type? Checkbox question example:
{type: 'checkbox',
text: 'question text',
answers: [
{text: 'first answer', checked: false},
{text: 'second answer', checked: true}
]}
And radio example:
{type: 'radio',
text: 'question text',
variants: ['wrong answer', 'right answer', 'wrong answer'],
answer: 1}//index of right variant
Upvotes: 1
Views: 58
Reputation: 142
You must create either both properties.
{type: 'checkbox',
text: 'question text',
answers: [
{text: 'first answer', checked: false},
{text: 'second answer', checked: true}
],
variants: ['wrong answer', 'right answer', 'wrong answer'],
answer: 1
}
or leave the subdoc schema as []. it will map any object. or simple
{}
Upvotes: 1