我有简单的代码尝试更新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。
文件结构
在更新之前,我试图通过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" => []
]
]