Skip to content

Commit

Permalink
Prefer writeConcern and readPreference options for execute methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jmikola committed Jan 29, 2025
1 parent 6149730 commit 9dac568
Show file tree
Hide file tree
Showing 32 changed files with 36 additions and 36 deletions.
2 changes: 1 addition & 1 deletion tests/bulk/write-0002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ $w = 1;
$wtimeout = 1000;
$writeConcern = new \MongoDB\Driver\WriteConcern($w, $wtimeout);
var_dump($insertBulk);
$result = $manager->executeBulkWrite(NS, $insertBulk, $writeConcern);
$result = $manager->executeBulkWrite(NS, $insertBulk, ['writeConcern' => $writeConcern]);
var_dump($insertBulk);

assert($result instanceof \MongoDB\Driver\WriteResult);
Expand Down
2 changes: 1 addition & 1 deletion tests/manager/manager-executeBulkWrite_error-003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ $bulk = new MongoDB\Driver\BulkWrite();
$bulk->insert(array('_id' => 1, 'x' => 1));

try {
$manager->executeBulkWrite(NS, $bulk, new MongoDB\Driver\WriteConcern(30));
$manager->executeBulkWrite(NS, $bulk, ['writeConcern' => new MongoDB\Driver\WriteConcern(30)]);
} catch (MongoDB\Driver\Exception\BulkWriteException $e) {
printf("BulkWriteException: %s\n", $e->getMessage());

Expand Down
2 changes: 1 addition & 1 deletion tests/readPreference/bug0146-001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ $rps = [

foreach($rps as $r) {
$rp = new MongoDB\Driver\ReadPreference($r);
$cursor = $manager->executeQuery(NS, new MongoDB\Driver\Query(array("my" => "query")), $rp);
$cursor = $manager->executeQuery(NS, new MongoDB\Driver\Query(['my' => 'query']), ['readPreference' => $rp]);
var_dump($cursor);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/replicaset/bug0155.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ $bulk = new MongoDB\Driver\BulkWrite();
$bulk->insert(array('example' => 'document'));

try {
$manager->executeBulkWrite(NS, $bulk, $wc);
$manager->executeBulkWrite(NS, $bulk, ['writeConcern' => $wc]);
} catch(MongoDB\Driver\Exception\BulkWriteException $e) {
var_dump($e->getWriteResult()->getWriteConcernError());
}
Expand Down
2 changes: 1 addition & 1 deletion tests/replicaset/readconcern-001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ $wc = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY);
$bulk = new MongoDB\Driver\BulkWrite();
$bulk->insert(['_id' => 1, 'x' => 1]);
$bulk->insert(['_id' => 2, 'x' => 2]);
$manager->executeBulkWrite(NS, $bulk, $wc);
$manager->executeBulkWrite(NS, $bulk, ['writeConcern' => $wc]);

$rc = new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::LOCAL);
$query = new MongoDB\Driver\Query(['x' => 2], ['readConcern' => $rc]);
Expand Down
2 changes: 1 addition & 1 deletion tests/replicaset/writeconcernerror-001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ $bulk->insert(array("my" => "value"));

$w = new MongoDB\Driver\WriteConcern(30, 100);
try {
$retval = $manager->executeBulkWrite(NS, $bulk, $w);
$retval = $manager->executeBulkWrite(NS, $bulk, ['writeConcern' => $w]);
} catch(MongoDB\Driver\Exception\BulkWriteException $e) {
$server = $e->getWriteResult()->getServer();
$server->getPort();
Expand Down
2 changes: 1 addition & 1 deletion tests/replicaset/writeconcernerror-002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ $bulk->update(array("foo" => "bar"), array('$set' => array("foo" => "baz")), arr

$w = new MongoDB\Driver\WriteConcern(30);
try {
$retval = $manager->executeBulkWrite(NS, $bulk, $w);
$retval = $manager->executeBulkWrite(NS, $bulk, ['writeConcern' => $w]);
} catch(MongoDB\Driver\Exception\BulkWriteException $e) {
printWriteResult($e->getWriteResult(), false);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/replicaset/writeresult-getserver-001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var_dump($server == $server2);

$rp = new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::SECONDARY);
/* Fetch a secondary */
$server3 = $manager->executeQuery(NS, new MongoDB\Driver\Query(array()), $rp)->getServer();
$server3 = $manager->executeQuery(NS, new MongoDB\Driver\Query([]), ['readPreference' => $rp])->getServer();

var_dump($server == $server3);
var_dump($server->getPort(), $server3->getPort());
Expand Down
2 changes: 1 addition & 1 deletion tests/replicaset/writeresult-getserver-002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var_dump($server == $server2);

$rp = new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::SECONDARY);
/* Fetch a secondary */
$server3 = $manager->executeQuery(NS, new MongoDB\Driver\Query(array()), $rp)->getServer();
$server3 = $manager->executeQuery(NS, new MongoDB\Driver\Query([]), ['readPreference' => $rp])->getServer();

var_dump($server == $server3);
var_dump($server->getPort(), $server3->getPort());
Expand Down
2 changes: 1 addition & 1 deletion tests/server/server-executeBulkWrite-002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ foreach ($writeConcerns as $writeConcern) {
$bulk = new MongoDB\Driver\BulkWrite();
$bulk->insert(array('wc' => $writeConcern));

$result = $primary->executeBulkWrite(NS, $bulk, new MongoDB\Driver\WriteConcern($writeConcern));
$result = $primary->executeBulkWrite(NS, $bulk, ['writeConcern' => new MongoDB\Driver\WriteConcern($writeConcern)]);
var_dump($result->isAcknowledged());
var_dump($result->getInsertedCount());
}
Expand Down
2 changes: 1 addition & 1 deletion tests/server/server-executeBulkWrite-003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ foreach ($writeConcerns as $wc) {
$bulk = new MongoDB\Driver\BulkWrite();
$bulk->insert(array('wc' => $wc));

$result = $server->executeBulkWrite(NS, $bulk, new MongoDB\Driver\WriteConcern($wc));
$result = $server->executeBulkWrite(NS, $bulk, ['writeConcern' => new MongoDB\Driver\WriteConcern($wc)]);
var_dump($result->isAcknowledged());
var_dump($result->getInsertedCount());
}
Expand Down
2 changes: 1 addition & 1 deletion tests/server/server-executeBulkWrite-004.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ foreach ($writeConcerns as $wc) {
$bulk->insert(array('wc' => $wc));

echo throws(function() use ($server, $bulk, $wc) {
$server->executeBulkWrite(NS, $bulk, new MongoDB\Driver\WriteConcern($wc));
$server->executeBulkWrite(NS, $bulk, ['writeConcern' => new MongoDB\Driver\WriteConcern($wc)]);
}, "MongoDB\Driver\Exception\RuntimeException"), "\n";
}

Expand Down
2 changes: 1 addition & 1 deletion tests/server/server-executeBulkWrite-005.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ foreach ($writeConcerns as $wc) {
$bulk = new MongoDB\Driver\BulkWrite();
$bulk->insert(array('wc' => $wc));

$result = $server->executeBulkWrite('local.' . COLLECTION_NAME, $bulk, new MongoDB\Driver\WriteConcern($wc));
$result = $server->executeBulkWrite('local.' . COLLECTION_NAME, $bulk, ['writeConcern' => new MongoDB\Driver\WriteConcern($wc)]);
var_dump($result->isAcknowledged());
var_dump($result->getInsertedCount());
}
Expand Down
4 changes: 2 additions & 2 deletions tests/server/server-executeCommand-002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ $command = new MongoDB\Driver\Command([
'pipeline' => [ [ '$match' => [ 'x' => 1 ] ] ],
'cursor' => (object) [],
]);
$secondary->executeCommand(DATABASE_NAME, $command, $rp);
$secondary->executeCommand(DATABASE_NAME, $command, ['readPreference' => $rp]);

$query = new MongoDB\Driver\Query(
array(
Expand All @@ -37,7 +37,7 @@ $query = new MongoDB\Driver\Query(
'limit' => 1,
)
);
$cursor = $secondary->executeQuery(DATABASE_NAME . '.system.profile', $query, $rp);
$cursor = $secondary->executeQuery(DATABASE_NAME . '.system.profile', $query, ['readPreference' => $rp]);
$profileEntry = current($cursor->toArray());

var_dump($profileEntry->command);
Expand Down
2 changes: 1 addition & 1 deletion tests/server/server-executeCommand-003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ $secondary = $manager->selectServer($secondaryRp);
* no effect when directly querying a server, since the secondaryOk flag is always
* set for hinted commands. */
$primaryRp = new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::PRIMARY);
$cursor = $secondary->executeCommand(DATABASE_NAME, new MongoDB\Driver\Command(array('ping' => 1)), $primaryRp);
$cursor = $secondary->executeCommand(DATABASE_NAME, new MongoDB\Driver\Command(array('ping' => 1)), ['readPreference' => $primaryRp]);

var_dump($cursor->toArray());

Expand Down
4 changes: 2 additions & 2 deletions tests/server/server-executeQuery-006.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if (empty($result->ok)) {
exit("Could not set profile level\n");
}

$secondary->executeQuery(NS, new MongoDB\Driver\Query(array("x" => 1)), $rp);
$secondary->executeQuery(NS, new MongoDB\Driver\Query(['x' => 1]), ['readPreference' => $rp]);

$query = new MongoDB\Driver\Query(
array(
Expand All @@ -36,7 +36,7 @@ $query = new MongoDB\Driver\Query(
'limit' => 1,
)
);
$cursor = $secondary->executeQuery(DATABASE_NAME . '.system.profile', $query, $rp);
$cursor = $secondary->executeQuery(DATABASE_NAME . '.system.profile', $query, ['readPreference' => $rp]);
$profileEntry = current($cursor->toArray());

if (! isset( $profileEntry->command )) {
Expand Down
4 changes: 2 additions & 2 deletions tests/server/server-executeQuery-008.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ $dataBearingNodes = count(array_filter($manager->getServers(), function (MongoDB

$bulk = new \MongoDB\Driver\BulkWrite;
$bulk->insert(['_id' => 1, 'x' => 1]);
$primary->executeBulkWrite(NS, $bulk, new MongoDB\Driver\WriteConcern($dataBearingNodes));
$primary->executeBulkWrite(NS, $bulk, ['writeConcern' => new MongoDB\Driver\WriteConcern($dataBearingNodes)]);

$secondaryRp = new MongoDB\Driver\ReadPreference(MongoDB\Driver\ReadPreference::SECONDARY);
$secondary = $manager->selectServer($secondaryRp);

/* Note: this is testing that the read preference (even a conflicting one) has
* no effect when directly querying a server, since the secondaryOk flag is always
* set for hinted queries. */
$cursor = $secondary->executeQuery(NS, new MongoDB\Driver\Query(['x' => 1]), $primaryRp);
$cursor = $secondary->executeQuery(NS, new MongoDB\Driver\Query(['x' => 1]), ['readPreference' => $primaryRp]);

var_dump($cursor->toArray());

Expand Down
4 changes: 2 additions & 2 deletions tests/standalone/bug0545.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ $page1->content = 'Lorem ipsum';
$book->pages[] = $page1;
$bulk = new MongoDB\Driver\BulkWrite;
$bulk->insert($book);
$result = $manager->executeBulkWrite(NS, $bulk, $wc);
$result = $manager->executeBulkWrite(NS, $bulk, ['writeConcern' => $wc]);
printf("Inserted %d document(s)\n", $result->getInsertedCount());

// Read
Expand All @@ -72,7 +72,7 @@ $page2->content = 'Dolor sit amet';
$bookAfterInsert->pages[] = $page2;
$bulk = new MongoDB\Driver\BulkWrite;
$bulk->update(['title' => $bookAfterInsert->title], $bookAfterInsert);
$result = $manager->executeBulkWrite(NS, $bulk, $wc);
$result = $manager->executeBulkWrite(NS, $bulk, ['writeConcern' => $wc]);
printf("Modified %d document(s)\n", $result->getModifiedCount());

// Read (again)
Expand Down
2 changes: 1 addition & 1 deletion tests/standalone/manager-as-singleton.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Database {
}

public function query($scheme, $query) {
return $this->Database->executeQuery($scheme, $query, new ReadPreference(ReadPreference::PRIMARY));
return $this->Database->executeQuery($scheme, $query, ['readPreference' => new ReadPreference(ReadPreference::PRIMARY)]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/standalone/write-error-001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ $w = 2;
$wtimeout = 1000;
$writeConcern = new \MongoDB\Driver\WriteConcern($w, $wtimeout);
echo throws(function() use($bulk, $writeConcern, $manager) {
$result = $manager->executeBulkWrite(NS, $bulk, $writeConcern);
$result = $manager->executeBulkWrite(NS, $bulk, ['writeConcern' => $writeConcern]);
}, "MongoDB\Driver\Exception\BulkWriteException"), "\n";

?>
Expand Down
2 changes: 1 addition & 1 deletion tests/standalone/writeresult-isacknowledged-003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ $manager = create_test_manager();

$bulk = new \MongoDB\Driver\BulkWrite;
$bulk->insert(array('x' => 2));
$result = $manager->executeBulkWrite(NS, $bulk, new MongoDB\Driver\WriteConcern(0));
$result = $manager->executeBulkWrite(NS, $bulk, ['writeConcern' => new MongoDB\Driver\WriteConcern(0)]);

printf("WriteResult::isAcknowledged(): %s\n", $result->isAcknowledged() ? 'true' : 'false');
var_dump($result);
Expand Down
2 changes: 1 addition & 1 deletion tests/writeConcernError/writeconcernerror-debug-001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ $bulk->insert(['x' => 1]);

try {
/* We assume that the replica set does not have 12 nodes */
$manager->executeBulkWrite(NS, $bulk, new MongoDB\Driver\WriteConcern(12));
$manager->executeBulkWrite(NS, $bulk, ['writeConcern' => new MongoDB\Driver\WriteConcern(12)]);
} catch(MongoDB\Driver\Exception\BulkWriteException $e) {
var_dump($e->getWriteResult()->getWriteConcernError());
}
Expand Down
2 changes: 1 addition & 1 deletion tests/writeConcernError/writeconcernerror-getcode-001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ $bulk->insert(['x' => 1]);

try {
/* We assume that the replica set does not have 12 nodes */
$manager->executeBulkWrite(NS, $bulk, new MongoDB\Driver\WriteConcern(12));
$manager->executeBulkWrite(NS, $bulk, ['writeConcern' => new MongoDB\Driver\WriteConcern(12)]);
} catch(MongoDB\Driver\Exception\BulkWriteException $e) {
var_dump($e->getWriteResult()->getWriteConcernError()->getCode());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ $bulk->insert(['x' => 1]);

try {
/* We assume that the replica set does not have 12 nodes */
$manager->executeBulkWrite(NS, $bulk, new MongoDB\Driver\WriteConcern(12));
$manager->executeBulkWrite(NS, $bulk, ['writeConcern' => new MongoDB\Driver\WriteConcern(12)]);
} catch(MongoDB\Driver\Exception\BulkWriteException $e) {
var_dump($e->getWriteResult()->getWriteConcernError()->getMessage());
}
Expand Down
2 changes: 1 addition & 1 deletion tests/writeResult/writeresult-debug-002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ $bulk->insert(['_id' => 3]);

try {
/* We assume that the replica set does not have 30 nodes */
$result = $manager->executeBulkWrite(NS, $bulk, new MongoDB\Driver\WriteConcern(30));
$result = $manager->executeBulkWrite(NS, $bulk, ['writeConcern' => new MongoDB\Driver\WriteConcern(30)]);
} catch (MongoDB\Driver\Exception\BulkWriteException $e) {
var_dump($e->getWriteResult());
}
Expand Down
2 changes: 1 addition & 1 deletion tests/writeResult/writeresult-getdeletedcount-002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ $bulk->update(['x' => 2], ['$set' => ['y' => 1]], ['upsert' => true]);
$bulk->update(['x' => 3], ['$set' => ['y' => 2]], ['upsert' => true]);
$bulk->delete(['x' => 1]);

$result = $manager->executeBulkWrite(NS, $bulk, new MongoDB\Driver\WriteConcern(0));
$result = $manager->executeBulkWrite(NS, $bulk, ['writeConcern' => new MongoDB\Driver\WriteConcern(0)]);

var_dump($result->getDeletedCount());

Expand Down
2 changes: 1 addition & 1 deletion tests/writeResult/writeresult-getinsertedcount-002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ $bulk->update(['x' => 2], ['$set' => ['y' => 1]], ['upsert' => true]);
$bulk->update(['x' => 3], ['$set' => ['y' => 2]], ['upsert' => true]);
$bulk->delete(['x' => 1]);

$result = $manager->executeBulkWrite(NS, $bulk, new MongoDB\Driver\WriteConcern(0));
$result = $manager->executeBulkWrite(NS, $bulk, ['writeConcern' => new MongoDB\Driver\WriteConcern(0)]);

var_dump($result->getInsertedCount());

Expand Down
2 changes: 1 addition & 1 deletion tests/writeResult/writeresult-getmatchedcount-002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ $bulk->update(['x' => 2], ['$set' => ['y' => 1]], ['upsert' => true]);
$bulk->update(['x' => 3], ['$set' => ['y' => 2]], ['upsert' => true]);
$bulk->delete(['x' => 1]);

$result = $manager->executeBulkWrite(NS, $bulk, new MongoDB\Driver\WriteConcern(0));
$result = $manager->executeBulkWrite(NS, $bulk, ['writeConcern' => new MongoDB\Driver\WriteConcern(0)]);

var_dump($result->getMatchedCount());

Expand Down
2 changes: 1 addition & 1 deletion tests/writeResult/writeresult-getmodifiedcount-002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ $bulk->update(['x' => 2], ['$set' => ['y' => 1]], ['upsert' => true]);
$bulk->update(['x' => 3], ['$set' => ['y' => 2]], ['upsert' => true]);
$bulk->delete(['x' => 1]);

$result = $manager->executeBulkWrite(NS, $bulk, new MongoDB\Driver\WriteConcern(0));
$result = $manager->executeBulkWrite(NS, $bulk, ['writeConcern' => new MongoDB\Driver\WriteConcern(0)]);

var_dump($result->getModifiedCount());

Expand Down
2 changes: 1 addition & 1 deletion tests/writeResult/writeresult-getupsertedcount-002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ $bulk->update(['x' => 2], ['$set' => ['y' => 1]], ['upsert' => true]);
$bulk->update(['x' => 3], ['$set' => ['y' => 2]], ['upsert' => true]);
$bulk->delete(['x' => 1]);

$result = $manager->executeBulkWrite(NS, $bulk, new MongoDB\Driver\WriteConcern(0));
$result = $manager->executeBulkWrite(NS, $bulk, ['writeConcern' => new MongoDB\Driver\WriteConcern(0)]);

var_dump($result->getUpsertedCount());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ $bulk->insert(['x' => 1]);

try {
/* We assume that the replica set does not have 12 nodes */
$result = $manager->executeBulkWrite(NS, $bulk, new MongoDB\Driver\WriteConcern(12));
$result = $manager->executeBulkWrite(NS, $bulk, ['writeConcern' => new MongoDB\Driver\WriteConcern(12)]);
} catch (MongoDB\Driver\Exception\BulkWriteException $e) {
var_dump($e->getWriteResult()->getWriteConcernError());
}
Expand Down
2 changes: 1 addition & 1 deletion tests/writeResult/writeresult-isacknowledged-001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ foreach ($wcs as $wc) {
$bulk = new MongoDB\Driver\BulkWrite;
$bulk->insert(['x' => 1]);

$result = $manager->executeBulkWrite(NS, $bulk, $wc);
$result = $manager->executeBulkWrite(NS, $bulk, ['writeConcern' => $wc]);

var_dump($result->isAcknowledged());
}
Expand Down

0 comments on commit 9dac568

Please sign in to comment.