2

I want to remove "answers" attribute of the below example. So It's possible to do so?

{
   _id: 1,
   results: [
      { item: "A", score: 5, answers: [ { q: 1, a: 4 }, { q: 2, a: 6 } ] },
      { item: "B", score: 8, answers: [ { q: 1, a: 8 }, { q: 2, a: 9 } ] }
   ]
}
{
   _id: 2,
   results: [
      { item: "C", score: 8, answers: [ { q: 1, a: 8 }, { q: 2, a: 7 } ] },
      { item: "B", score: 4, answers: [ { q: 1, a: 0 }, { q: 2, a: 8 } ] }
   ]
}

The expected result:

{
   _id: 1,
   results: [
      { item: "A", score: 5 },
      { item: "B", score: 8 }
   ]
}
{
   _id: 2,
   results: [
      { item: "C", score: 8 },
      { item: "B", score: 4 }
   ]
}
buræquete
  • 14,226
  • 4
  • 44
  • 89
English learner
  • 192
  • 1
  • 9
  • Possible duplicate http://stackoverflow.com/questions/4669178/how-to-update-multiple-array-elements-in-mongodb with the update operator as `$unset` – chridam Apr 28 '17 at 08:32

0 Answers0