【发布时间】:2020-06-29 11:23:06
【问题描述】:
我正在将我的 mongo 类转换为 mongoDB 管理驱动程序,当我尝试执行更新命令时出现以下错误
Error:
---------------------------------
Fatal error: Uncaught Error: Call to undefined method MongoDB\Driver\Manager::executeUpdate()
This is my code
--------------------------------
$where = array('status'=>1);
$set = array('status'=>2)
$updateOptions = array("multi" => true);
$writeConcern = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 100);
$manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
$result = $manager->executeUpdate("mydb.collection", $where, $set, $updateOptions, $writeConcern);
我也试过 $manager->executeBulkWrite
Here is the code
----------------------------
$where = array('status'=>1);
$set = array('status'=>2)
$updateOptions = array("multi" => true);
$bulk = new MongoDB\Driver\BulkWrite();
$bulk->update($where,$set,['multiple' => true, 'upsert' => false]);
$result = $manager->executeBulkWrite($db.'.'.$collection, $bulk);
I am trying to execute $manager->executeBulkWrite on two collections same time and i got the error below
Fatal error: Uncaught MongoDB\Driver\Exception\InvalidArgumentException: BulkWrite objects may only be executed once and this instance has already been executed
谁能帮我解决这个问题,或者更新 MongoDB\Driver\Manager 中记录的任何其他替代方法
【问题讨论】:
标签: php mongodb mongodb-query