[英]Updating MongoDB Document Not Working
我只是試圖更新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);
沒用 我收到此消息:致命錯誤: Call to a member function update() on array in...
這里發生了什么?
<?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);
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.