Skip to content

Commit 95a2523

Browse files
committed
DOCSP-49976 Update Documents
1 parent c7bb8c1 commit 95a2523

File tree

3 files changed

+41
-8
lines changed

3 files changed

+41
-8
lines changed

source/crud/query/retrieve.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ following methods:
130130
.. _golang-find-example:
131131

132132
Find Example
133-
````````````
133+
------------
134134

135135
The following example passes a context, filter, and ``FindOptions`` to
136136
the ``Find()`` method, which performs the following actions:
@@ -158,7 +158,7 @@ the ``Find()`` method, which performs the following actions:
158158
.. _golang-find-one-example:
159159

160160
Find One Example
161-
````````````````
161+
----------------
162162

163163
The following example passes a context, filter, and ``FindOneOptions``
164164
to the ``FindOne()`` method, which performs the following actions:
@@ -185,7 +185,7 @@ to the ``FindOne()`` method, which performs the following actions:
185185
.. _golang-find-one-by-id:
186186

187187
Find One by ObjectId Example
188-
````````````````````````````
188+
----------------------------
189189

190190
This example defines an ``id`` variable with a value of type ``ObjectId``
191191
and uses ``id`` to specify a query filter. The filter matches a document

source/crud/update.txt

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.. _golang-update:
33

44
================
5-
Modify Documents
5+
Update Documents
66
================
77

88
.. facet::
@@ -150,8 +150,8 @@ changes.
150150
See our :ref:`upsert guide <golang-upsert-guide>`
151151
to learn how to insert a new document if no documents match the query filter.
152152

153-
Example
154-
```````
153+
UpdateOne() Example
154+
-------------------
155155

156156
The following document describes an employee:
157157

@@ -167,7 +167,7 @@ The following document describes an employee:
167167
...
168168
}
169169

170-
The following example uses the ``UpdateByID()`` method to:
170+
The following example uses the ``UpdateOne()`` method to:
171171

172172
- Match the document where the ``_id`` value is 2158.
173173
- Set the ``name`` field to "Mary Wollstonecraft Shelley" and the
@@ -209,6 +209,39 @@ The following shows the updated document resulting from the preceding update ope
209209
...
210210
}
211211

212+
UpdateMany() Example
213+
--------------------
214+
215+
The following example uses the ``listingsAndReviews`` collection in the
216+
``sample_airbnb`` dataset from the :atlas:`Atlas sample datasets </sample-data>`.
217+
The example performs the following on the ``listingsAndReviews`` collection:
218+
219+
- Matches documents in which the market field of the address subdocument, ``address.market`` is "Sydney"
220+
- Updates the ``price`` in the matched documents by 1.15 times
221+
222+
.. literalinclude:: /includes/usage-examples/code-snippets/updateMany.go
223+
:start-after: begin updatemany
224+
:end-before: end updatemany
225+
:emphasize-lines: 9
226+
:language: go
227+
:copyable:
228+
:dedent:
229+
230+
After you run the example, you can find the following updated
231+
documents in the ``listingsAndReviews`` collection:
232+
233+
.. code-block:: json
234+
:copyable: false
235+
236+
// results truncated
237+
...
238+
{ "_id" : "10091713", ... , "name" : "Surry Hills Studio", ... , "price" : 181.00, ... },
239+
{ "_id" : "9908871", ... , "name" : "Family friendly beach house", ... , "price" : 751.00, ... },
240+
{ "_id" : "20989061", ... , "name" : "Big and sunny Narraben room", ... , "price" : 60.00, ... },
241+
...
242+
243+
For an example on how to find multiple documents, see :ref:`golang-find-example`.
244+
212245
.. _golang-replacement-document:
213246

214247
Replace

source/includes/usage-examples/code-snippets/updateMany.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ func main() {
4646
if err != nil {
4747
panic(err)
4848
}
49-
// end updatemany
5049

5150
// Prints the number of updated documents
5251
fmt.Printf("Documents updated: %v\n", result.ModifiedCount)
52+
// end updatemany
5353

5454
// When you run this file for the first time, it should print:
5555
// Number of documents replaced: 609

0 commit comments

Comments
 (0)