Php 更新MongoDB文档不起作用
我只是尝试更新MongoDB数据库文档中的特定字段 我有以下代码:Php 更新MongoDB文档不起作用,php,mongodb,mongodb-query,Php,Mongodb,Mongodb Query,我只是尝试更新MongoDB数据库文档中的特定字段 我有以下代码: $connection = new MongoClient("private"); $collection = $connection->testdb->deliveries; // Use the ID to generate the actual MongoID $realmongoid = new MongoId($id); $cursor = $collection-&g
$connection = new MongoClient("private");
$collection = $connection->testdb->deliveries;
// Use the ID to generate the actual MongoID
$realmongoid = new MongoId($id);
$cursor = $collection->findOne(array('_id' => $realmongoid));
所有这些都很好,但当我尝试用以下代码更新文档中的特定字段时:
$arrayWithDriverInfo = array("filledBy" => $_SESSION['username']);
$cursor->update($arrayWithDriverInfo);
它不起作用。我收到这样一条消息:致命错误:调用…中数组上的成员函数update()
这里发生了什么?尝试在中使用操作符,如下所示
<?php
$connection = new MongoClient("private");
$collection = $connection->testdb->deliveries;
$obj = $collection->findOne();
$id = "55711efed0103b1598140076";
$realmongoid = new MongoId($id);
$arrayWithDriverInfo = array("filledBy" => $_SESSION['username']);
$collection->update(
array( '_id' => $realmongoid ),
array( '$set' => $arrayWithDriverInfo )
);
$obj = $collection->findOne();
var_dump($obj);
?>
尝试在中使用操作符,如下所示
<?php
$connection = new MongoClient("private");
$collection = $connection->testdb->deliveries;
$obj = $collection->findOne();
$id = "55711efed0103b1598140076";
$realmongoid = new MongoId($id);
$arrayWithDriverInfo = array("filledBy" => $_SESSION['username']);
$collection->update(
array( '_id' => $realmongoid ),
array( '$set' => $arrayWithDriverInfo )
);
$obj = $collection->findOne();
var_dump($obj);
?>