I have the following code
$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('MyCollection', $bulkWrite);
The code returns the error:
Exception:not authorized on db to execute command { update:
What is the issue?
After reviewing the code I found that the issue is in the name of the collection.
If we have before:
$DB_CONNECTION_STRING="mongodb://dbName:dbPassword";
require '../../vendor/autoload.php';
$mongoConn = new MongoDB\Driver\Manager( $DB_CONNECTION_STRING );
Then after we need to have the correct reference to the 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);