@@ -59,6 +59,12 @@ class Watch implements Executable, /* @internal */ CommandSubscriber
59
59
{
60
60
public const FULL_DOCUMENT_DEFAULT = 'default ' ;
61
61
public const FULL_DOCUMENT_UPDATE_LOOKUP = 'updateLookup ' ;
62
+ public const FULL_DOCUMENT_WHEN_AVAILABLE = 'whenAvailable ' ;
63
+ public const FULL_DOCUMENT_REQUIRED = 'required ' ;
64
+
65
+ public const FULL_DOCUMENT_BEFORE_CHANGE_OFF = 'off ' ;
66
+ public const FULL_DOCUMENT_BEFORE_CHANGE_WHEN_AVAILABLE = 'whenAvailable ' ;
67
+ public const FULL_DOCUMENT_BEFORE_CHANGE_REQUIRED = 'required ' ;
62
68
63
69
/** @var integer */
64
70
private static $ wireVersionForStartAtOperationTime = 7 ;
@@ -105,15 +111,33 @@ class Watch implements Executable, /* @internal */ CommandSubscriber
105
111
*
106
112
* * collation (document): Specifies a collation.
107
113
*
108
- * * fullDocument (string): Determines whether the "fullDocument" field
109
- * will be populated for update operations. By default, change streams
110
- * only return the delta of fields during the update operation (via the
111
- * "updateDescription" field). To additionally return the most current
112
- * majority-committed version of the updated document, specify
113
- * "updateLookup" for this option. Defaults to "default".
114
+ * * fullDocument (string): Determines how the "fullDocument" response
115
+ * field will be populated for update operations.
116
+ *
117
+ * By default, change streams only return the delta of fields (via an
118
+ * "updateDescription" field) for update operations and "fullDocument" is
119
+ * omitted. Insert and replace operations always include the
120
+ * "fullDocument" field. Delete operations omit the field as the document
121
+ * no longer exists.
122
+ *
123
+ * Specify "updateLookup" to return the current majority-committed
124
+ * version of the updated document.
125
+ *
126
+ * MongoDB 6.0+ allows returning the post-image of the modified document
127
+ * if the collection has changeStreamPreAndPostImages enabled. Specify
128
+ * "whenAvailable" to return the post-image if available or a null value
129
+ * if not. Specify "required" to return the post-image if available or
130
+ * raise an error if not.
114
131
*
115
- * Insert and replace operations always include the "fullDocument" field
116
- * and delete operations omit the field as the document no longer exists.
132
+ * * fullDocumentBeforeChange (string): Determines how the
133
+ * "fullDocumentBeforeChange" response field will be populated. By
134
+ * default, the field is omitted.
135
+ *
136
+ * MongoDB 6.0+ allows returning the pre-image of the modified document
137
+ * if the collection has changeStreamPreAndPostImages enabled. Specify
138
+ * "whenAvailable" to return the pre-image if available or a null value
139
+ * if not. Specify "required" to return the pre-image if available or
140
+ * raise an error if not.
117
141
*
118
142
* * maxAwaitTimeMS (integer): The maximum amount of time for the server to
119
143
* wait on new documents to satisfy a change stream query.
@@ -181,6 +205,10 @@ public function __construct(Manager $manager, $databaseName, $collectionName, ar
181
205
throw InvalidArgumentException::invalidType ('"fullDocument" option ' , $ options ['fullDocument ' ], 'string ' );
182
206
}
183
207
208
+ if (isset ($ options ['fullDocumentBeforeChange ' ]) && ! is_string ($ options ['fullDocumentBeforeChange ' ])) {
209
+ throw InvalidArgumentException::invalidType ('"fullDocumentBeforeChange" option ' , $ options ['fullDocumentBeforeChange ' ], 'string ' );
210
+ }
211
+
184
212
if (! $ options ['readPreference ' ] instanceof ReadPreference) {
185
213
throw InvalidArgumentException::invalidType ('"readPreference" option ' , $ options ['readPreference ' ], ReadPreference::class);
186
214
}
@@ -212,7 +240,7 @@ public function __construct(Manager $manager, $databaseName, $collectionName, ar
212
240
}
213
241
214
242
$ this ->aggregateOptions = array_intersect_key ($ options , ['batchSize ' => 1 , 'collation ' => 1 , 'maxAwaitTimeMS ' => 1 , 'readConcern ' => 1 , 'readPreference ' => 1 , 'session ' => 1 , 'typeMap ' => 1 ]);
215
- $ this ->changeStreamOptions = array_intersect_key ($ options , ['fullDocument ' => 1 , 'resumeAfter ' => 1 , 'startAfter ' => 1 , 'startAtOperationTime ' => 1 ]);
243
+ $ this ->changeStreamOptions = array_intersect_key ($ options , ['fullDocument ' => 1 , 'fullDocumentBeforeChange ' => 1 , ' resumeAfter ' => 1 , 'startAfter ' => 1 , 'startAtOperationTime ' => 1 ]);
216
244
217
245
// Null database name implies a cluster-wide change stream
218
246
if ($ databaseName === null ) {
0 commit comments