doucou19961205 2018-06-28 05:55
浏览 147
已采纳

如何使用php从mongodb文件中删除或删除数组数据

Here are the JSON i want to delete { points: 55, bonus: 20 } from points

{
       _id: 3,
       name: "ahn",
       age: 22,
       type: 2,
       status: "A",
       favorites: { artist: "Cassatt", food: "cake" },
       finished: [ 6 ],
       badges: [ "blue", "red" ],
       points: [
          { points: 81, bonus: 8 },
          { points: 55, bonus: 20 },
          { points: 56, bonus: 25 }
       ]
}

I want to see this result

{
       _id: 3,
       name: "ahn",
       age: 22,
       type: 2,
       status: "A",
       favorites: { artist: "Cassatt", food: "cake" },
       finished: [ 6 ],
       badges: [ "blue", "red" ],
       points: [
          { points: 81, bonus: 8 },
          { points: 56, bonus: 25 }
       ]
}
  • 写回答

2条回答 默认 最新

  • douruyun8153 2018-06-28 06:08
    关注

    You can use $pull of MongoDB

        db.collection.update(
          { },
          { $pull: { points:  { points: 55, bonus: 20 } } },
        )
    

    {multi: true}: adding this in above query will delete all entries matching { points: 55, bonus: 20 }

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?