使用PHP在MongoDB中进行Update,UpdateOne

时间:2019-04-08 16:14:20

标签: php database mongodb

我正在尝试使用PHP在Mongo DB上使用ID更新内容。通过Update,UpdateMany,BulkWrite,我尝试更新内容,但仍然遇到问题。

批量写入错误:

Fatal error: Uncaught MongoDB\Driver\Exception\InvalidArgumentException: Cannot do an empty bulk write in C:\xampp\htdocs\phpmongodb\update1.php:32 Stack trace: #0 C:\xampp\htdocs\phpmongodb\update1.php(32): MongoDB\Driver\Manager->executeBulkWrite('hospitaldb.doct...', Object(MongoDB\Driver\BulkWrite)) #1 {main} thrown in C:\xampp\htdocs\phpmongodb\update1.php on line 32

更新错误:

Fatal error: Uncaught Error: Call to undefined method MongoDB\Collection::update() in C:\xampp\htdocs\phpmongodb\update1.php:30 Stack trace: #0 {main} thrown in C:\xampp\htdocs\phpmongodb\update1.php on line 30

我分别执行了这两个命令。

$manager = new MongoDB\Driver\Manager('mongodb://localhost:27017');
$bulk = new MongoDB\Driver\BulkWrite;

$mycollection->executeBulkWrite(['_id' => new \MongoDB\BSON\ObjectID($_SESSION['$id'])], ['$set' => ['$password' => $newpass]]);

$manager->executeBulkWrite($mycollection, $bulk);

0 个答案:

没有答案