Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 更新MongoDB文档不起作用_Php_Mongodb_Mongodb Query - Fatal编程技术网

Php 更新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

我只是尝试更新MongoDB数据库文档中的特定字段

我有以下代码:

    $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);

?>