Skip to content

Commit dcb3190

Browse files
authored
PHPLIB-814: Change stream support for point-in-time pre and post-images (#911)
Introduces fullDocumentBeforeChange option. Tests for specifying "whenAvailable" and "required" for both fullDocument and fullDocumentBeforeChange (requires MongoDB 6.0+ with changeStreamPreAndPostImages enabled on the collection). Intentionally omits mention of FULL_DOCUMENT_DEFAULT (related to PHPLIB-808) and FULL_DOCUMENT_BEFORE_CHANGE_OFF constants, since those redundantly specified default behavior. Tests synced with mongodb/specifications@8978899
1 parent c9f96d7 commit dcb3190

4 files changed

+63
-6
lines changed

source/includes/apiargs-MongoDBClient-method-watch-option.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ source:
1111
file: apiargs-method-watch-option.yaml
1212
ref: fullDocument
1313
---
14+
source:
15+
file: apiargs-method-watch-option.yaml
16+
ref: fullDocumentBeforeChange
17+
post: |
18+
.. versionadded: 1.13
19+
---
1420
source:
1521
file: apiargs-method-watch-option.yaml
1622
ref: maxAwaitTimeMS

source/includes/apiargs-MongoDBCollection-method-watch-option.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ source:
1111
file: apiargs-method-watch-option.yaml
1212
ref: fullDocument
1313
---
14+
source:
15+
file: apiargs-method-watch-option.yaml
16+
ref: fullDocumentBeforeChange
17+
post: |
18+
.. versionadded: 1.13
19+
---
1420
source:
1521
file: apiargs-method-watch-option.yaml
1622
ref: maxAwaitTimeMS

source/includes/apiargs-MongoDBDatabase-method-watch-option.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ source:
1111
file: apiargs-method-watch-option.yaml
1212
ref: fullDocument
1313
---
14+
source:
15+
file: apiargs-method-watch-option.yaml
16+
ref: fullDocumentBeforeChange
17+
post: |
18+
.. versionadded: 1.13
19+
---
1420
source:
1521
file: apiargs-method-watch-option.yaml
1622
ref: maxAwaitTimeMS

source/includes/apiargs-method-watch-option.yaml

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,53 @@ arg_name: option
1313
name: fullDocument
1414
type: string
1515
description: |
16-
Allowed values are 'default' and 'updateLookup'. Defaults to 'default'.
17-
When set to 'updateLookup', the change notification for partial updates will
18-
include both a delta describing the changes to the document, as well as a
19-
copy of the entire document that was changed from some time after the change
20-
occurred. The following values are supported:
16+
Determines how the "fullDocument" response field will be populated for update
17+
operations.
18+
19+
By default, change streams only return the delta of fields (via an
20+
"udateDescription" field) for update operations and "fullDocument" is omitted.
21+
Insert and replace operations always include the "fullDocument" field. Delete
22+
operations omit the field as the document no longer exists.
23+
24+
Specify "updateLookup" to return the current majority-committed version of the
25+
updated document.
26+
27+
MongoDB 6.0+ allows returning the post-image of the modified document if the
28+
collection has ``changeStreamPreAndPostImages`` enabled. Specify
29+
"whenAvailable" to return the post-image if available or a null value if not.
30+
Specify "required" to return the post-image if available or raise an error if
31+
not.
32+
33+
The following values are supported:
2134
22-
- ``MongoDB\Operation\Watch::FULL_DOCUMENT_DEFAULT`` (*default*)
2335
- ``MongoDB\Operation\Watch::FULL_DOCUMENT_UPDATE_LOOKUP``
36+
- ``MongoDB\Operation\Watch::FULL_DOCUMENT_WHEN_AVAILABLE``
37+
- ``MongoDB\Operation\Watch::FULL_DOCUMENT_REQUIRED``
38+
39+
.. note::
40+
41+
This is an option of the ``$changeStream`` pipeline stage.
42+
interface: phpmethod
43+
operation: ~
44+
optional: true
45+
---
46+
arg_name: option
47+
name: fullDocumentBeforeChange
48+
type: string
49+
description: |
50+
Determines how the "fullDocumentBeforeChange" response field will be
51+
populated. By default, the field is omitted.
52+
53+
MongoDB 6.0+ allows returning the pre-image of the modified document if the
54+
collection has ``changeStreamPreAndPostImages`` enabled. Specify
55+
"whenAvailable" to return the pre-image if available or a null value if not.
56+
Specify "required" to return the pre-image if available or raise an error if
57+
not.
58+
59+
The following values are supported:
60+
61+
- ``MongoDB\Operation\Watch::FULL_DOCUMENT_BEFORE_CHANGE_WHEN_AVAILABLE``
62+
- ``MongoDB\Operation\Watch::FULL_DOCUMENT_BEFORE_CHANGE_REQUIRED``
2463
2564
.. note::
2665

0 commit comments

Comments
 (0)