1717
1818namespace MongoDB \Operation ;
1919
20- use MongoDB \ChangeStream as ChangeStreamResult ;
20+ use MongoDB \ChangeStream ;
2121use MongoDB \Driver \Command ;
2222use MongoDB \Driver \Manager ;
2323use MongoDB \Driver \ReadConcern ;
3232 * Operation for creating a change stream with the aggregate command.
3333 *
3434 * @api
35- * @see \MongoDB\Collection::changeStream ()
36- * @see http ://docs.mongodb.org /manual/reference/command/changeStream /
35+ * @see \MongoDB\Collection::watch ()
36+ * @see https ://docs.mongodb.com /manual/changeStreams /
3737 */
38- class ChangeStream implements Executable
38+ class Watch implements Executable
3939{
4040 const FULL_DOCUMENT_DEFAULT = 'default ' ;
4141 const FULL_DOCUMENT_UPDATE_LOOKUP = 'updateLookup ' ;
@@ -47,18 +47,19 @@ class ChangeStream implements Executable
4747 private $ manager ;
4848
4949 /**
50- * Constructs a changeStream command.
50+ * Constructs an aggregate command for creating a change stream .
5151 *
5252 * Supported options:
5353 *
54- * * fullDocument (string): Allowed values: ‘default’, ‘updateLookup’.
55- * Defaults to ‘default’. When set to ‘updateLookup’, the change
56- * notification for partial updates will include both a delta describing
57- * the changes to the document, as well as a copy of the entire document
58- * that was changed from some time after the change occurred. For forward
59- * compatibility, a driver MUST NOT raise an error when a user provides
60- * an unknown value. The driver relies on the server to validate this
61- * option.
54+ * * fullDocument (string): Determines whether the "fullDocument" field
55+ * will be populated for update operations. By default, change streams
56+ * only return the delta of fields during the update operation (via the
57+ * "updateDescription" field). To additionally return the most current
58+ * majority-committed version of the updated document, specify
59+ * "updateLookup" for this option. Defaults to "default".
60+ *
61+ * Insert and replace operations always include the "fullDocument" field
62+ * and delete operations omit the field as the document no longer exists.
6263 *
6364 * * resumeAfter (document): Specifies the logical starting point for the
6465 * new change stream.
@@ -69,7 +70,9 @@ class ChangeStream implements Executable
6970 * This is not supported for server versions < 3.2 and will result in an
7071 * exception at execution time if used.
7172 *
72- * * readPreference (MongoDB\Driver\ReadPreference): Read preference.
73+ * * readPreference (MongoDB\Driver\ReadPreference): Read preference. This
74+ * will be used to select a new server when resuming. Defaults to a
75+ * "primary" read preference.
7376 *
7477 * * maxAwaitTimeMS (integer): The maximum amount of time for the server to
7578 * wait on new documents to satisfy a change stream query.
@@ -91,8 +94,13 @@ class ChangeStream implements Executable
9194 * @param Manager $manager Manager instance from the driver
9295 * @throws InvalidArgumentException for parameter/option parsing errors
9396 */
94- public function __construct ($ databaseName , $ collectionName , array $ pipeline , array $ options = [], Manager $ manager )
97+ public function __construct (Manager $ manager , $ databaseName , $ collectionName , array $ pipeline , array $ options = [])
9598 {
99+ $ options += [
100+ 'fullDocument ' => self ::FULL_DOCUMENT_DEFAULT ,
101+ 'readPreference ' => new ReadPreference (ReadPreference::RP_PRIMARY ),
102+ ];
103+
96104 if (isset ($ options ['batchSize ' ]) && ! is_integer ($ options ['batchSize ' ])) {
97105 throw InvalidArgumentException::invalidType ('"batchSize" option ' , $ options ['batchSize ' ], 'integer ' );
98106 }
@@ -119,19 +127,19 @@ public function __construct($databaseName, $collectionName, array $pipeline, arr
119127 }
120128 }
121129
130+ $ this ->manager = $ manager ;
122131 $ this ->databaseName = (string ) $ databaseName ;
123132 $ this ->collectionName = (string ) $ collectionName ;
124133 $ this ->pipeline = $ pipeline ;
125134 $ this ->options = $ options ;
126- $ this ->manager = $ manager ;
127135 }
128136
129137 /**
130138 * Execute the operation.
131139 *
132140 * @see Executable::execute()
133141 * @param Server $server
134- * @return ChangeStreamResult
142+ * @return ChangeStream
135143 * @throws UnexpectedValueException if the command response was malformed
136144 * @throws UnsupportedException if collation, read concern, or write concern is used and unsupported
137145 * @throws DriverRuntimeException for other driver errors (e.g. connection errors)
@@ -142,7 +150,7 @@ public function execute(Server $server)
142150
143151 $ cursor = $ command ->execute ($ server );
144152
145- return new ChangeStreamResult ($ cursor , $ this ->createResumeCallable ());
153+ return new ChangeStream ($ cursor , $ this ->createResumeCallable ());
146154 }
147155
148156 private function createAggregateOptions ()
0 commit comments