I have a collection called 'A' with thousands of documents in it. Here grades is the array of sub documents which consist attribute questions which is array of number like below
{ "_id" : 1,
"grades" : [
{ type: "quiz", questions: [ 10, 8, 5 ] },
{ type: "quiz", questions: [ 8, 9, 6 ] },
{ type: "hw", questions: [ 5, 4, 3 ] },
{ type: "exam", questions: [ 25, 10, 23, 0 ] }
]
}
In order to add additional feature we have to modify the format of questions and make it array of documents which has two fields one is number (which will inherit the old data) and another one is attempts(by default it will be empty array and may have value 'P'- Pass or 'F'- Fail). After this transformation the document should look like below
{ "_id" : 1,
"grades" : [
{
type: "quiz",
questions:[
{ number: 10, attempts: ['F', 'P'] },
{ number: 8, attempts: [] },
{ number: 5, attempts: ['P'] }
]
},
{
type: "quiz",
questions:
[
{ number: 8, attempts: ['F', 'P'] },
{ number: 9, attempts: [] },
{ number: 6, attempts: ['P'] }
]
},
{
type: "hw",
questions:
[
{ number: 5, attempts: ['F', 'P'] },
{ number: 4, attempts: [] },
{ number: 3, attempts: ['P'] }
]
},
{
type: "exam",
questions:
[
{ number: 25, attempts: ['F', 'P'] },
{ number: 10, attempts: [] },
{ number: 23, attempts: ['P'] },
{ number: 0, attempts: ['P', 'P'] }
]
}
]
}
Appreciate for all the help