17
17
18
18
namespace MongoDB \Operation ;
19
19
20
- use MongoDB \ChangeStream as ChangeStreamResult ;
20
+ use MongoDB \ChangeStream ;
21
21
use MongoDB \Driver \Command ;
22
22
use MongoDB \Driver \Manager ;
23
23
use MongoDB \Driver \ReadConcern ;
32
32
* Operation for creating a change stream with the aggregate command.
33
33
*
34
34
* @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 /
37
37
*/
38
- class ChangeStream implements Executable
38
+ class Watch implements Executable
39
39
{
40
40
const FULL_DOCUMENT_DEFAULT = 'default ' ;
41
41
const FULL_DOCUMENT_UPDATE_LOOKUP = 'updateLookup ' ;
@@ -47,18 +47,19 @@ class ChangeStream implements Executable
47
47
private $ manager ;
48
48
49
49
/**
50
- * Constructs a changeStream command.
50
+ * Constructs an aggregate command for creating a change stream .
51
51
*
52
52
* Supported options:
53
53
*
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.
62
63
*
63
64
* * resumeAfter (document): Specifies the logical starting point for the
64
65
* new change stream.
@@ -69,7 +70,9 @@ class ChangeStream implements Executable
69
70
* This is not supported for server versions < 3.2 and will result in an
70
71
* exception at execution time if used.
71
72
*
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.
73
76
*
74
77
* * maxAwaitTimeMS (integer): The maximum amount of time for the server to
75
78
* wait on new documents to satisfy a change stream query.
@@ -91,8 +94,13 @@ class ChangeStream implements Executable
91
94
* @param Manager $manager Manager instance from the driver
92
95
* @throws InvalidArgumentException for parameter/option parsing errors
93
96
*/
94
- public function __construct ($ databaseName , $ collectionName , array $ pipeline , array $ options = [], Manager $ manager )
97
+ public function __construct (Manager $ manager , $ databaseName , $ collectionName , array $ pipeline , array $ options = [])
95
98
{
99
+ $ options += [
100
+ 'fullDocument ' => self ::FULL_DOCUMENT_DEFAULT ,
101
+ 'readPreference ' => new ReadPreference (ReadPreference::RP_PRIMARY ),
102
+ ];
103
+
96
104
if (isset ($ options ['batchSize ' ]) && ! is_integer ($ options ['batchSize ' ])) {
97
105
throw InvalidArgumentException::invalidType ('"batchSize" option ' , $ options ['batchSize ' ], 'integer ' );
98
106
}
@@ -119,19 +127,19 @@ public function __construct($databaseName, $collectionName, array $pipeline, arr
119
127
}
120
128
}
121
129
130
+ $ this ->manager = $ manager ;
122
131
$ this ->databaseName = (string ) $ databaseName ;
123
132
$ this ->collectionName = (string ) $ collectionName ;
124
133
$ this ->pipeline = $ pipeline ;
125
134
$ this ->options = $ options ;
126
- $ this ->manager = $ manager ;
127
135
}
128
136
129
137
/**
130
138
* Execute the operation.
131
139
*
132
140
* @see Executable::execute()
133
141
* @param Server $server
134
- * @return ChangeStreamResult
142
+ * @return ChangeStream
135
143
* @throws UnexpectedValueException if the command response was malformed
136
144
* @throws UnsupportedException if collation, read concern, or write concern is used and unsupported
137
145
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
@@ -142,7 +150,7 @@ public function execute(Server $server)
142
150
143
151
$ cursor = $ command ->execute ($ server );
144
152
145
- return new ChangeStreamResult ($ cursor , $ this ->createResumeCallable ());
153
+ return new ChangeStream ($ cursor , $ this ->createResumeCallable ());
146
154
}
147
155
148
156
private function createAggregateOptions ()
0 commit comments