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条)

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改