@@ -50,7 +50,8 @@ const CHANGE_STREAM_OPTIONS = [
50
50
'resumeAfter' ,
51
51
'startAfter' ,
52
52
'startAtOperationTime' ,
53
- 'fullDocument'
53
+ 'fullDocument' ,
54
+ 'fullDocumentBeforeChange'
54
55
] as const ;
55
56
56
57
const CURSOR_OPTIONS = [
@@ -131,11 +132,35 @@ export type ChangeStreamAggregateRawResult<TChange> = {
131
132
*/
132
133
export interface ChangeStreamOptions extends AggregateOptions {
133
134
/**
134
- * Allowed values: 'updateLookup'. When set to 'updateLookup',
135
- * the change stream will include both a delta describing the changes to the document,
136
- * as well as a copy of the entire document that was changed from some time after the change occurred.
135
+ * Allowed values: 'updateLookup', 'whenAvailable', 'required'.
136
+ *
137
+ * When set to 'updateLookup', the change notification for partial updates
138
+ * will include both a delta describing the changes to the document as well
139
+ * as a copy of the entire document that was changed from some time after
140
+ * the change occurred.
141
+ *
142
+ * When set to 'whenAvailable', configures the change stream to return the
143
+ * post-image of the modified document for replace and update change events
144
+ * if the post-image for this event is available.
145
+ *
146
+ * When set to 'required', the same behavior as 'whenAvailable' except that
147
+ * an error is raised if the post-image is not available.
137
148
*/
138
149
fullDocument ?: string ;
150
+
151
+ /**
152
+ * Allowed values: 'whenAvailable', 'required', 'off'.
153
+ *
154
+ * The default is to not send a value, which is equivalent to 'off'.
155
+ *
156
+ * When set to 'whenAvailable', configures the change stream to return the
157
+ * pre-image of the modified document for replace, update, and delete change
158
+ * events if it is available.
159
+ *
160
+ * When set to 'required', the same behavior as 'whenAvailable' except that
161
+ * an error is raised if the pre-image is not available.
162
+ */
163
+ fullDocumentBeforeChange ?: string ;
139
164
/** The maximum amount of time for the server to wait on new documents to satisfy a change stream query. */
140
165
maxAwaitTimeMS ?: number ;
141
166
/**
@@ -230,15 +255,23 @@ export interface ChangeStreamUpdateDocument<TSchema extends Document = Document>
230
255
operationType : 'update' ;
231
256
/**
232
257
* This is only set if `fullDocument` is set to `'updateLookup'`
233
- * The fullDocument document represents the most current majority-committed version of the updated document.
234
- * The fullDocument document may vary from the document at the time of the update operation depending on the
235
- * number of interleaving majority-committed operations that occur between the update operation and the document lookup .
258
+ * Contains the point-in-time post-image of the modified document if the
259
+ * post-image is available and either 'required' or 'whenAvailable' was
260
+ * specified for the 'fullDocument' option when creating the change stream .
236
261
*/
237
262
fullDocument ?: TSchema ;
238
263
/** Contains a description of updated and removed fields in this operation */
239
264
updateDescription : UpdateDescription < TSchema > ;
240
265
/** Namespace the update event occured on */
241
266
ns : ChangeStreamNameSpace ;
267
+ /**
268
+ * Contains the pre-image of the modified or deleted document if the
269
+ * pre-image is available for the change event and either 'required' or
270
+ * 'whenAvailable' was specified for the 'fullDocumentBeforeChange' option
271
+ * when creating the change stream. If 'whenAvailable' was specified but the
272
+ * pre-image is unavailable, this will be explicitly set to null.
273
+ */
274
+ fullDocumentBeforeChange ?: TSchema ;
242
275
}
243
276
244
277
/**
@@ -254,6 +287,14 @@ export interface ChangeStreamReplaceDocument<TSchema extends Document = Document
254
287
fullDocument : TSchema ;
255
288
/** Namespace the replace event occured on */
256
289
ns : ChangeStreamNameSpace ;
290
+ /**
291
+ * Contains the pre-image of the modified or deleted document if the
292
+ * pre-image is available for the change event and either 'required' or
293
+ * 'whenAvailable' was specified for the 'fullDocumentBeforeChange' option
294
+ * when creating the change stream. If 'whenAvailable' was specified but the
295
+ * pre-image is unavailable, this will be explicitly set to null.
296
+ */
297
+ fullDocumentBeforeChange ?: TSchema ;
257
298
}
258
299
259
300
/**
@@ -267,6 +308,14 @@ export interface ChangeStreamDeleteDocument<TSchema extends Document = Document>
267
308
operationType : 'delete' ;
268
309
/** Namespace the delete event occured on */
269
310
ns : ChangeStreamNameSpace ;
311
+ /**
312
+ * Contains the pre-image of the modified or deleted document if the
313
+ * pre-image is available for the change event and either 'required' or
314
+ * 'whenAvailable' was specified for the 'fullDocumentBeforeChange' option
315
+ * when creating the change stream. If 'whenAvailable' was specified but the
316
+ * pre-image is unavailable, this will be explicitly set to null.
317
+ */
318
+ fullDocumentBeforeChange ?: TSchema ;
270
319
}
271
320
272
321
/**
0 commit comments