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

时间:2017-05-21 14:43:46

标签: php mongodb mongoose

我有以下文件:

class Person{
    String id;
    HashMap<String, Person> friends = new HashMap<>();

    public void addFriend(String id, Person friend){
       friends.put(id, friend);
    }
    ...
}

HashMap<String, Person> people = new HashMap<>();

我需要按键"parameters" : [ { "592193d6470e6cf80d3c9874" : { "Speed" : "1", "Acceleration" : "2" } }] 拉取元素。

我试过了:

592193d6470e6cf80d3c9874

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

1 个答案:

答案 0 :(得分:1)

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

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