MongoDB:如何删除数组的对象属性

时间:2017-04-28 07:38:40

标签: mongodb mongodb-query

我想删除以下示例的“answers”属性。 那么有可能这样做吗?

{
   _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 } ] }
   ]
}

预期结果:

{
   _id: 1,
   results: [
      { item: "A", score: 5 },
      { item: "B", score: 8 }
   ]
}
{
   _id: 2,
   results: [
      { item: "C", score: 8 },
      { item: "B", score: 4 }
   ]
}

0 个答案:

没有答案
相关问题