Skip to content

PHPLIB-240: FindAndModify should throw for unsupported write concern #293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ source:
file: apiargs-MongoDBCollection-common-option.yaml
ref: writeConcern
post: |
This is not supported for server versions prior to 3.2 and will be ignored if
used.
This is not supported for server versions prior to 3.2 and will result in an
exception at execution time if used.
...
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ source:
file: apiargs-MongoDBCollection-common-option.yaml
ref: writeConcern
post: |
This is not supported for server versions prior to 3.2 and will be ignored if
used.
This is not supported for server versions prior to 3.2 and will result in an
exception at execution time if used.
...
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ source:
file: apiargs-MongoDBCollection-common-option.yaml
ref: writeConcern
post: |
This is not supported for server versions prior to 3.2 and will be ignored if
used.
This is not supported for server versions prior to 3.2 and will result in an
exception at execution time if used.
...
15 changes: 8 additions & 7 deletions src/Operation/FindAndModify.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ class FindAndModify implements Executable
*
* * writeConcern (MongoDB\Driver\WriteConcern): Write concern.
*
* This is not supported for server versions < 3.2.
* This is not supported for server versions < 3.2 and will result in an
* exception at execution time if used.
*
* @param string $databaseName Database name
* @param string $collectionName Collection name
Expand Down Expand Up @@ -144,7 +145,7 @@ public function __construct($databaseName, $collectionName, array $options)
* @param Server $server
* @return object|null
* @throws UnexpectedValueException if the command response was malformed
* @throws UnsupportedException if collation is used and unsupported
* @throws UnsupportedException if collation or write concern is used and unsupported
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
public function execute(Server $server)
Expand All @@ -153,6 +154,10 @@ public function execute(Server $server)
throw UnsupportedException::collationNotSupported();
}

if (isset($this->options['writeConcern']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForWriteConcern)) {
throw UnsupportedException::writeConcernNotSupported();
}

$cursor = $server->executeCommand($this->databaseName, $this->createCommand($server));
$result = current($cursor->toArray());

Expand Down Expand Up @@ -209,11 +214,7 @@ private function createCommand(Server $server)
$cmd['bypassDocumentValidation'] = $this->options['bypassDocumentValidation'];
}

/* In the future, we should throw an exception if the "writeConcern"
* option is specified and not supported by the server (see: SPEC-494).
* For BC in 1.x, we will silently omit it for incompatible servers.
*/
if (isset($this->options['writeConcern']) && \MongoDB\server_supports_feature($server, self::$wireVersionForWriteConcern)) {
if (isset($this->options['writeConcern'])) {
$cmd['writeConcern'] = \MongoDB\write_concern_as_document($this->options['writeConcern']);
}

Expand Down
8 changes: 5 additions & 3 deletions src/Operation/FindOneAndDelete.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ class FindOneAndDelete implements Executable
* * sort (document): Determines which document the operation modifies if
* the query selects multiple documents.
*
* * writeConcern (MongoDB\Driver\WriteConcern): Write concern. This option
* is only supported for server versions >= 3.2.
* * writeConcern (MongoDB\Driver\WriteConcern): Write concern.
*
* This is not supported for server versions < 3.2 and will result in an
* exception at execution time if used.
*
* @param string $databaseName Database name
* @param string $collectionName Collection name
Expand Down Expand Up @@ -75,7 +77,7 @@ public function __construct($databaseName, $collectionName, $filter, array $opti
* @see Executable::execute()
* @param Server $server
* @return object|null
* @throws UnsupportedException if collation is used and unsupported
* @throws UnsupportedException if collation or write concern is used and unsupported
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
public function execute(Server $server)
Expand Down
8 changes: 5 additions & 3 deletions src/Operation/FindOneAndReplace.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ class FindOneAndReplace implements Executable
* * upsert (boolean): When true, a new document is created if no document
* matches the query. The default is false.
*
* * writeConcern (MongoDB\Driver\WriteConcern): Write concern. This option
* is only supported for server versions >= 3.2.
* * writeConcern (MongoDB\Driver\WriteConcern): Write concern.
*
* This is not supported for server versions < 3.2 and will result in an
* exception at execution time if used.
*
* @param string $databaseName Database name
* @param string $collectionName Collection name
Expand Down Expand Up @@ -115,7 +117,7 @@ public function __construct($databaseName, $collectionName, $filter, $replacemen
* @see Executable::execute()
* @param Server $server
* @return object|null
* @throws UnsupportedException if collation is used and unsupported
* @throws UnsupportedException if collation or write concern is used and unsupported
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
public function execute(Server $server)
Expand Down
8 changes: 5 additions & 3 deletions src/Operation/FindOneAndUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ class FindOneAndUpdate implements Executable
* * upsert (boolean): When true, a new document is created if no document
* matches the query. The default is false.
*
* * writeConcern (MongoDB\Driver\WriteConcern): Write concern. This option
* is only supported for server versions >= 3.2.
* * writeConcern (MongoDB\Driver\WriteConcern): Write concern.
*
* This is not supported for server versions < 3.2 and will result in an
* exception at execution time if used.
*
* @param string $databaseName Database name
* @param string $collectionName Collection name
Expand Down Expand Up @@ -115,7 +117,7 @@ public function __construct($databaseName, $collectionName, $filter, $update, ar
* @see Executable::execute()
* @param Server $server
* @return object|null
* @throws UnsupportedException if collation is used and unsupported
* @throws UnsupportedException if collation or write concern is used and unsupported
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
*/
public function execute(Server $server)
Expand Down