Commit 689d9437 authored by Jeremy Mikola's avatar Jeremy Mikola

Default values for fullDocument and readPreference Watch options

Refactoring the change stream tests to execute Watch directly highlighted a bug where no read preference was available during the resume process. This ensures that a read preference is always set, and also specifies a "fullDocument" default (consistent with other drivers).
parent d9858d1f
...@@ -51,14 +51,15 @@ class Watch implements Executable ...@@ -51,14 +51,15 @@ class Watch implements Executable
* *
* Supported options: * Supported options:
* *
* * fullDocument (string): Allowed values: ‘default’, ‘updateLookup’. * * fullDocument (string): Determines whether the "fullDocument" field
* Defaults to ‘default’. When set to ‘updateLookup’, the change * will be populated for update operations. By default, change streams
* notification for partial updates will include both a delta describing * only return the delta of fields during the update operation (via the
* the changes to the document, as well as a copy of the entire document * "updateDescription" field). To additionally return the most current
* that was changed from some time after the change occurred. For forward * majority-committed version of the updated document, specify
* compatibility, a driver MUST NOT raise an error when a user provides * "updateLookup" for this option. Defaults to "default".
* an unknown value. The driver relies on the server to validate this *
* option. * Insert and replace operations always include the "fullDocument" field
* and delete operations omit the field as the document no longer exists.
* *
* * resumeAfter (document): Specifies the logical starting point for the * * resumeAfter (document): Specifies the logical starting point for the
* new change stream. * new change stream.
...@@ -69,7 +70,9 @@ class Watch implements Executable ...@@ -69,7 +70,9 @@ class Watch implements Executable
* This is not supported for server versions < 3.2 and will result in an * This is not supported for server versions < 3.2 and will result in an
* exception at execution time if used. * exception at execution time if used.
* *
* * readPreference (MongoDB\Driver\ReadPreference): Read preference. * * readPreference (MongoDB\Driver\ReadPreference): Read preference. This
* will be used to select a new server when resuming. Defaults to a
* "primary" read preference.
* *
* * maxAwaitTimeMS (integer): The maximum amount of time for the server to * * maxAwaitTimeMS (integer): The maximum amount of time for the server to
* wait on new documents to satisfy a change stream query. * wait on new documents to satisfy a change stream query.
...@@ -93,6 +96,11 @@ class Watch implements Executable ...@@ -93,6 +96,11 @@ class Watch implements Executable
*/ */
public function __construct(Manager $manager, $databaseName, $collectionName, array $pipeline, array $options = []) public function __construct(Manager $manager, $databaseName, $collectionName, array $pipeline, array $options = [])
{ {
$options += [
'fullDocument' => self::FULL_DOCUMENT_DEFAULT,
'readPreference' => new ReadPreference(ReadPreference::RP_PRIMARY),
];
if (isset($options['batchSize']) && ! is_integer($options['batchSize'])) { if (isset($options['batchSize']) && ! is_integer($options['batchSize'])) {
throw InvalidArgumentException::invalidType('"batchSize" option', $options['batchSize'], 'integer'); throw InvalidArgumentException::invalidType('"batchSize" option', $options['batchSize'], 'integer');
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment