在检查代码后,我发现问题出在集合的名称中。
如果我们以前有过:
$DB_CONNECTION_STRING="mongodb://dbName:dbPassword";
require '../../vendor/autoload.php';
$mongoConn = new MongoDB\Driver\Manager( $DB_CONNECTION_STRING );
然后在需要正确引用dbname之后:
$bulkWrite=new MongoDB\Driver\BulkWrite;
$filter = ['name' => 'John'];
$update = ['$set' => ['name' => 'Smith', age: 35, profession => 'pilot']];
$options = array('multi' => false, 'upsert' => false);
$bulkWrite->update($filter, $options);
$mongoConn->executeBulkWrite('dbName.MyCollection', $bulkWrite);