@@ -56,7 +56,7 @@ parameter and a pipeline parameter. To return all changes, pass in an empty Pipe
56
56
Example
57
57
~~~~~~~
58
58
59
- The following example opens a change stream on the ``tea.ratings`` collection and
59
+ The following example opens a change stream on the ``tea.ratings`` collection and
60
60
outputs all changes:
61
61
62
62
.. code-block:: go
@@ -76,13 +76,13 @@ outputs all changes:
76
76
}
77
77
78
78
If you modify the ``tea.ratings`` collection in a separate shell, this code will print
79
- your changes. Inserting a document with a ``type`` value of ``"White Peony"`` and a
79
+ your changes. Inserting a document with a ``type`` value of ``"White Peony"`` and a
80
80
``rating`` value of ``4`` will output the following change event:
81
-
81
+
82
82
.. code-block:: go
83
83
:copyable: false
84
84
85
- map[_id:map[_data:...] clusterTime: {...} documentKey:map[_id:ObjectID("...")]
85
+ map[_id:map[_data:...] clusterTime: {...} documentKey:map[_id:ObjectID("...")]
86
86
fullDocument:map[_id:ObjectID("...") rating:4 type:White Peony] ns:
87
87
map[coll:ratings db:tea] operationType:insert]
88
88
@@ -91,7 +91,7 @@ Modify the Change Stream Output
91
91
92
92
Use the pipeline parameter to modify the change stream output. This parameter allows you to
93
93
only watch for certain change events. Format the pipeline parameter as an array of documents,
94
- with each document representing an aggregation stage.
94
+ with each document representing an aggregation stage.
95
95
96
96
You can use the following pipeline stages in this parameter:
97
97
@@ -125,13 +125,13 @@ new delete operations:
125
125
fmt.Println(changeStream.Current)
126
126
}
127
127
128
- If you delete the ``tea.ratings`` document with a ``type`` value of
128
+ If you delete the ``tea.ratings`` document with a ``type`` value of
129
129
``"White Peony"`` in a separate shell, this code will output the following:
130
130
131
131
.. code-block:: go
132
132
:copyable: false
133
-
134
- {"_id": {"_data": "..."},"operationType": "delete","clusterTime":
133
+
134
+ {"_id": {"_data": "..."},"operationType": "delete","clusterTime":
135
135
{"$timestamp":{"t":"...","i":"..."}},"ns": {"db": "tea","coll": "ratings"},
136
136
"documentKey": {"_id": {"$oid":"..."}}}
137
137
@@ -144,7 +144,7 @@ If you delete the ``tea.ratings`` document with a ``type`` value of
144
144
Modify the Behavior of Watch()
145
145
------------------------------
146
146
147
- Use an opts parameter to modify the behavior of the ``Watch()`` method.
147
+ Use an opts parameter to modify the behavior of the ``Watch()`` method.
148
148
149
149
You can specify the following options in the opts parameter:
150
150
@@ -156,39 +156,39 @@ You can specify the following options in the opts parameter:
156
156
- ``Collation``
157
157
- ``StartAtOperationTime``
158
158
159
- For more information on these fields, visit the
159
+ For more information on these fields, visit the
160
160
:manual:`MongoDB manual </reference/method/Mongo.watch/#mongodb-method-Mongo.watch>`.
161
161
162
162
Example
163
163
~~~~~~~
164
164
165
- The following example calls the ``Watch()`` method on the ``tea.ratings`` collection. It
165
+ The following example calls the ``Watch()`` method on the ``tea.ratings`` collection. It
166
166
specifies the ``FullDocument`` opts parameter to output a copy of the entire modified document:
167
167
168
168
.. code-block:: go
169
169
170
- coll := client.Database("tea").Collection("ratings")
171
- opts := options.ChangeStream().SetFullDocument(options.UpdateLookup)
170
+ coll := client.Database("tea").Collection("ratings")
171
+ opts := options.ChangeStream().SetFullDocument(options.UpdateLookup)
172
172
173
- changeStream, err := coll.Watch(context.TODO(), mongo.Pipeline{}, opts)
174
- if err != nil {
175
- panic(err)
176
- }
177
- defer changeStream.Close(context.TODO())
173
+ changeStream, err := coll.Watch(context.TODO(), mongo.Pipeline{}, opts)
174
+ if err != nil {
175
+ panic(err)
176
+ }
177
+ defer changeStream.Close(context.TODO())
178
178
179
- for changeStream.Next(context.TODO()) {
180
- fmt.Println(changeStream.Current)
181
- }
179
+ for changeStream.Next(context.TODO()) {
180
+ fmt.Println(changeStream.Current)
181
+ }
182
182
183
- If you update the ``rating`` value of the ``"Masala"`` tea from ``10`` to ``9``,
184
- this code outputs the following:
183
+ If you update the ``rating`` value of the ``"Masala"`` tea from ``10`` to ``9``,
184
+ this code outputs the following:
185
185
186
186
.. code-block:: go
187
187
:copyable: false
188
188
189
189
{"_id": {"_data": "..."},"operationType": "update","clusterTime": {"$timestamp":
190
190
{"t":"...","i":"..."}},"fullDocument": {"_id": {"$oid":"..."},"type": "Masala","rating":
191
- {"$numberInt":"9"}}, "ns": {"db": "tea","coll": "ratings"},"documentKey": {"_id":
191
+ {"$numberInt":"9"}}, "ns": {"db": "tea","coll": "ratings"},"documentKey": {"_id":
192
192
{"$oid":"..."}}, "updateDescription": {"updatedFields": {"rating": {"$numberInt":"9"}},
193
193
"removedFields": [],"truncatedArrays": []}}
194
194
@@ -209,4 +209,4 @@ To learn more about the ``Watch()`` method, visit the following API documentatio
209
209
210
210
- `Watch() for collections <{+api+}/mongo#Collection.Watch>`__
211
211
- `Watch() for databases <{+api+}/mongo#Database.Watch>`__
212
- - `Watch() for clients <{+api+}/mongo#Client.Watch>`__
212
+ - `Watch() for clients <{+api+}/mongo#Client.Watch>`__
0 commit comments