dongsiju1941
dongsiju1941
2017-05-21 14:43

如何从数组MongoDB php中提取元素?

已采纳

I have the following document:

"parameters" : [
    {
        "592193d6470e6cf80d3c9874" : {
            "Speed" : "1",
            "Acceleration" : "2"
        }
    }]

I need to pull element by key 592193d6470e6cf80d3c9874.

I tried:

 $this->collection->update(
            [],
            ['$unset' => ['parameters' => $id]], ['multiple' => true]);

Where $id id 592193d6470e6cf80d3c9874.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • dongren4758 dongren4758 4年前
    $this->collection->update(['$unset' => ['parameters'=> ['_id'] => $id], ['multiple' => true]);
    

    or

    $this->collection->update(['$unset' => ['parameters.'.$parameterId => null]], ['multiple' => true]);
    
    点赞 评论 复制链接分享