更新Mongodb中的数据时出错?

时间:2017-06-29 10:15:59

标签: php mongodb mongodb-query

我有简单的代码尝试更新MongoDB中的数据:

$this->collection->update(
            ["_id" => new \MongoId($id)],
            ['$set' => ['value_default' => $data]]);

它有一个错误:

localhost:27017: Found $id field without a $ref before it, which is invalid.

$data是数组。 $id是主键的字符串ID。

文件结构

enter image description here

在更新之前,我试图通过id获取文档:

 $cursor= $this->collection->find(array("_id" => new \MongoID($id)));

它给我一个对象。

我尝试将$data看起来像:

array:2 [
  0 => array:8 [
    "id" => "594146d2b3569eb653851895"
    "unique_id" => array:1 [
      "$id" => "5954d6dfb3569ef41f7f42cf"
    ]
    "type_value" => "float"
    "prefix" => "probability"
    "title" => "Вероятность"
    "type" => "1"
    "value" => "1"
    "nodes" => []
  ]
  1 => array:8 [
    "id" => "5941499fb3569e6454851896"
    "unique_id" => array:1 [
      "$id" => "5954d6dfb3569ef41f7f42d0"
    ]
    "type_value" => "float"
    "prefix" => "playerArc"
    "title" => "Арка игрока"
    "type" => "1"
    "value" => "2"
    "nodes" => []
  ]
]

0 个答案:

没有答案