@@ -21,11 +21,11 @@ Overview
21
21
--------
22
22
23
23
In this guide, you can learn how to use a **change stream** to monitor real-time
24
- changes to your database . A change stream is a {+mdb-server+} feature that
24
+ changes to your data . A change stream is a {+mdb-server+} feature that
25
25
allows your application to subscribe to data changes on a collection, database,
26
26
or deployment.
27
27
28
- When using the {+driver-short +}, you can instantiate a ``MongoDB\ChangeStream`` to
28
+ When using the {+php-library +}, you can instantiate a ``MongoDB\ChangeStream`` to
29
29
monitor data changes.
30
30
31
31
Sample Data
@@ -49,8 +49,8 @@ Open a Change Stream
49
49
--------------------
50
50
51
51
To open a change stream, call the ``watch()`` method. The instance on which you
52
- call the ``watch()`` method on determines the scope of events that the change
53
- stream listens for . You can call the ``watch()`` method on the following
52
+ call the ``watch()`` method determines the scope of events that the change
53
+ stream monitors . You can call the ``watch()`` method on the following
54
54
classes:
55
55
56
56
- ``MongoDB\Client``: Monitor all changes in the MongoDB deployment
@@ -84,11 +84,10 @@ as it occurs. The printed change event resembles the following output:
84
84
.. code-block:: bash
85
85
:copyable: false
86
86
87
- { "_id" : { "_data" : "..." }, "operationType" : "update", "clusterTime" :
88
- { "$timestamp" : { ... }, "wallTime" : { "$date" : ... }, "ns" :
89
- { "db" : "sample_restaurants", "coll" : "restaurants" }, "documentKey" :
90
- { "_id" : { "$oid" : "..." } }, "updateDescription" : { "updatedFields" :
91
- { "cuisine" : "Irish" }, "removedFields" : [ ], "truncatedArrays" : [ ] } }
87
+ {"_id":{"_data":"..."},"operationType":"update","clusterTime":{"$timestamp":{...},
88
+ "wallTime":{"$date":...},"ns":{"db":"sample_restaurants","coll":"restaurants"},
89
+ "documentKey":{"_id":{"$oid":"..."}},"updateDescription":{"updatedFields":
90
+ {"cuisine":"Irish"},"removedFields":[],"truncatedArrays":[]}}}
92
91
93
92
Modify the Change Stream Output
94
93
-------------------------------
@@ -144,7 +143,7 @@ you can set in the array:
144
143
| Each change stream event document includes a resume token as the ``_id``
145
144
field. Pass the entire ``_id`` field of the change event document that
146
145
represents the operation you want to resume after.
147
- | ``resume_after`` is mutually exclusive with ``startAfter`` and ``startAtOperationTime``.
146
+ | This option is mutually exclusive with ``startAfter`` and ``startAtOperationTime``.
148
147
149
148
* - ``startAfter``
150
149
- | Instructs ``watch()`` to start a new change stream after the
@@ -153,17 +152,17 @@ you can set in the array:
153
152
| Each change stream event document includes a resume token as the ``_id``
154
153
field. Pass the entire ``_id`` field of the change event document that
155
154
represents the operation you want to resume after.
156
- | ``start_after`` is mutually exclusive with ``resume_after `` and ``start_at_operation_time ``.
155
+ | This option is mutually exclusive with ``resumeAfter `` and ``startAtOperationTime ``.
157
156
158
157
* - ``typeMap``
159
- - | Sets the maximum number of change events to return in each batch of the
160
- response from the MongoDB cluster .
158
+ - | The type map to apply to cursors, which determines how BSON documents are converted
159
+ to PHP values .
161
160
162
161
* - ``collation``
163
162
- | Sets the collation to use for the change stream cursor.
164
163
165
164
For a full list of ``watch()`` options, see `MongoDB\\Collection::watch()
166
- <{+api+}/reference/ method/MongoDBCollection-watch/>`__ in the API
165
+ <{+api+}/method/MongoDBCollection-watch/>`__ in the API
167
166
documentation.
168
167
169
168
.. _php-change-stream-pre-post-image:
@@ -184,26 +183,26 @@ options in an array parameter to ``watch()``.
184
183
185
184
The **pre-image** is the full version of a document *before* a change. To include the
186
185
pre-image in the change stream event, set the ``fullDocumentBeforeChange`` field
187
- to one of the following strings :
186
+ to one of the following values :
188
187
189
188
- ``MongoDB\Operation\Watch::FULL_DOCUMENT_BEFORE_CHANGE_WHEN_AVAILABLE``: The change event includes
190
189
a pre-image of the modified document for change events. If the pre-image is not available, this
191
190
change event field has a ``null`` value.
192
191
- ``MongoDB\Operation\Watch::FULL_DOCUMENT_BEFORE_CHANGE_REQUIRED``: The change event includes a pre-image
193
192
of the modified document for change events. If the pre-image is not available, the
194
- {+driver-short +} raises an error.
193
+ {+php-library +} raises an error.
195
194
196
195
The **post-image** is the full version of a document *after* a change. To include the
197
196
post-image in the change stream event, set the ``fullDocument`` field to
198
- one of the following strings :
197
+ one of the following values :
199
198
200
199
- ``MongoDB\Operation\Watch::FULL_DOCUMENT_UPDATE_LOOKUP``: The change event includes a
201
- copy of the entire changed document from some time after the change.
200
+ copy of the entire changed document from some time after the change.
202
201
- ``MongoDB\Operation\Watch::FULL_DOCUMENT_WHEN_AVAILABLE``: The change event includes
203
202
a post-image of the modified document for change events only if the post-image is available.
204
203
- ``MongoDB\Operation\Watch::FULL_DOCUMENT_REQUIRED``: The change event includes a post-image
205
204
of the modified document for change events. If the post-image is not available, the
206
- {+driver-short +} raises an error.
205
+ {+php-library +} raises an error.
207
206
208
207
The following example calls the ``watch()`` method on a collection and includes the post-image
209
208
of updated documents by setting the ``fullDocument`` option:
@@ -221,17 +220,15 @@ code:
221
220
222
221
.. code-block:: bash
223
222
:copyable: false
224
- :emphasize-lines: 3,4,5,6
225
-
226
- { "_id" : { "_data" : "..." }, "operationType" : "update", "clusterTime" :
227
- { "$timestamp" : { ... } }, "wallTime" : { "$date" : ... },
228
- "fullDocument" : { "_id" : { "$oid" : "..." }, "address" : { "building" : "202-24",
229
- "coord" : [ -73.925044200000002093, 40.559546199999999772 ], "street" :
230
- "Rockaway Point Boulevard", "zipcode" : "11697" }, "borough" : "Queens", "cuisine" :
231
- "Irish", "grades" : [ ... ], "name" : "Blarney Castle", "restaurant_id" : "40366356" },
232
- "ns" : { "db" : "sample_restaurants", "coll" : "restaurants" }, "documentKey" :
233
- { "_id" : { "$oid" : "..." } }, "updateDescription" : { "updatedFields" :
234
- { "cuisine" : "Irish" }, "removedFields" : [ ], "truncatedArrays" : [ ] } }
223
+ :emphasize-lines: 2-5
224
+
225
+ {"_id":{"_data":"..."},"operationType":"update","clusterTime":...},"wallTime":{"$date":...},
226
+ "fullDocument":{"_id":{"$oid":"..."},"address": {"building":"202-24","coord":
227
+ [-73.925044200000002093,40.559546199999999772], "street":"Rockaway Point Boulevard",
228
+ "zipcode":"11697"},"borough":"Queens","cuisine":"Irish","grades":[...],"name":"Blarney Castle",
229
+ "restaurant_id":"40366356"},"ns":{"db":"sample_restaurants","coll":"restaurants"},
230
+ "documentKey":{"_id":{"$oid":"..."}},"updateDescription":{"updatedFields":{"cuisine":"Irish"},
231
+ "removedFields":[],"truncatedArrays":[]}}
235
232
236
233
.. tip::
237
234
0 commit comments