Skip to content

Commit 89742f3

Browse files
committed
Merge pull request mongodb#293
2 parents 7cf9454 + fcb17e8 commit 89742f3

7 files changed

+29
-22
lines changed

docs/includes/apiargs-MongoDBCollection-method-findOneAndDelete-option.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ source:
1818
file: apiargs-MongoDBCollection-common-option.yaml
1919
ref: writeConcern
2020
post: |
21-
This is not supported for server versions prior to 3.2 and will be ignored if
22-
used.
21+
This is not supported for server versions prior to 3.2 and will result in an
22+
exception at execution time if used.
2323
...

docs/includes/apiargs-MongoDBCollection-method-findOneAndReplace-option.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ source:
3939
file: apiargs-MongoDBCollection-common-option.yaml
4040
ref: writeConcern
4141
post: |
42-
This is not supported for server versions prior to 3.2 and will be ignored if
43-
used.
42+
This is not supported for server versions prior to 3.2 and will result in an
43+
exception at execution time if used.
4444
...

docs/includes/apiargs-MongoDBCollection-method-findOneAndUpdate-option.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ source:
3939
file: apiargs-MongoDBCollection-common-option.yaml
4040
ref: writeConcern
4141
post: |
42-
This is not supported for server versions prior to 3.2 and will be ignored if
43-
used.
42+
This is not supported for server versions prior to 3.2 and will result in an
43+
exception at execution time if used.
4444
...

src/Operation/FindAndModify.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ class FindAndModify implements Executable
6969
*
7070
* * writeConcern (MongoDB\Driver\WriteConcern): Write concern.
7171
*
72-
* This is not supported for server versions < 3.2.
72+
* This is not supported for server versions < 3.2 and will result in an
73+
* exception at execution time if used.
7374
*
7475
* @param string $databaseName Database name
7576
* @param string $collectionName Collection name
@@ -144,7 +145,7 @@ public function __construct($databaseName, $collectionName, array $options)
144145
* @param Server $server
145146
* @return object|null
146147
* @throws UnexpectedValueException if the command response was malformed
147-
* @throws UnsupportedException if collation is used and unsupported
148+
* @throws UnsupportedException if collation or write concern is used and unsupported
148149
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
149150
*/
150151
public function execute(Server $server)
@@ -153,6 +154,10 @@ public function execute(Server $server)
153154
throw UnsupportedException::collationNotSupported();
154155
}
155156

157+
if (isset($this->options['writeConcern']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForWriteConcern)) {
158+
throw UnsupportedException::writeConcernNotSupported();
159+
}
160+
156161
$cursor = $server->executeCommand($this->databaseName, $this->createCommand($server));
157162
$result = current($cursor->toArray());
158163

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

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

src/Operation/FindOneAndDelete.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ class FindOneAndDelete implements Executable
3737
* * sort (document): Determines which document the operation modifies if
3838
* the query selects multiple documents.
3939
*
40-
* * writeConcern (MongoDB\Driver\WriteConcern): Write concern. This option
41-
* is only supported for server versions >= 3.2.
40+
* * writeConcern (MongoDB\Driver\WriteConcern): Write concern.
41+
*
42+
* This is not supported for server versions < 3.2 and will result in an
43+
* exception at execution time if used.
4244
*
4345
* @param string $databaseName Database name
4446
* @param string $collectionName Collection name
@@ -75,7 +77,7 @@ public function __construct($databaseName, $collectionName, $filter, array $opti
7577
* @see Executable::execute()
7678
* @param Server $server
7779
* @return object|null
78-
* @throws UnsupportedException if collation is used and unsupported
80+
* @throws UnsupportedException if collation or write concern is used and unsupported
7981
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
8082
*/
8183
public function execute(Server $server)

src/Operation/FindOneAndReplace.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ class FindOneAndReplace implements Executable
5252
* * upsert (boolean): When true, a new document is created if no document
5353
* matches the query. The default is false.
5454
*
55-
* * writeConcern (MongoDB\Driver\WriteConcern): Write concern. This option
56-
* is only supported for server versions >= 3.2.
55+
* * writeConcern (MongoDB\Driver\WriteConcern): Write concern.
56+
*
57+
* This is not supported for server versions < 3.2 and will result in an
58+
* exception at execution time if used.
5759
*
5860
* @param string $databaseName Database name
5961
* @param string $collectionName Collection name
@@ -115,7 +117,7 @@ public function __construct($databaseName, $collectionName, $filter, $replacemen
115117
* @see Executable::execute()
116118
* @param Server $server
117119
* @return object|null
118-
* @throws UnsupportedException if collation is used and unsupported
120+
* @throws UnsupportedException if collation or write concern is used and unsupported
119121
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
120122
*/
121123
public function execute(Server $server)

src/Operation/FindOneAndUpdate.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ class FindOneAndUpdate implements Executable
5252
* * upsert (boolean): When true, a new document is created if no document
5353
* matches the query. The default is false.
5454
*
55-
* * writeConcern (MongoDB\Driver\WriteConcern): Write concern. This option
56-
* is only supported for server versions >= 3.2.
55+
* * writeConcern (MongoDB\Driver\WriteConcern): Write concern.
56+
*
57+
* This is not supported for server versions < 3.2 and will result in an
58+
* exception at execution time if used.
5759
*
5860
* @param string $databaseName Database name
5961
* @param string $collectionName Collection name
@@ -115,7 +117,7 @@ public function __construct($databaseName, $collectionName, $filter, $update, ar
115117
* @see Executable::execute()
116118
* @param Server $server
117119
* @return object|null
118-
* @throws UnsupportedException if collation is used and unsupported
120+
* @throws UnsupportedException if collation or write concern is used and unsupported
119121
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
120122
*/
121123
public function execute(Server $server)

0 commit comments

Comments
 (0)