Skip to content

Commit 2dee410

Browse files
committed
headings
1 parent 4df22ee commit 2dee410

File tree

1 file changed

+31
-23
lines changed

1 file changed

+31
-23
lines changed

source/crud/update.txt

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.. _golang-change-document:
22
.. _golang-update:
3+
.. _golang-update-documents:
34

45
================
56
Update Documents
@@ -56,28 +57,23 @@ The driver provides the following methods to update documents:
5657
* ``UpdateOne()``
5758
* ``UpdateMany()``
5859

59-
A Note About ``_id``
60-
~~~~~~~~~~~~~~~~~~~~
60+
Use the ``UpdateOne()`` or ``UpdateByID()`` method to update a single
61+
document.
62+
63+
Use the ``UpdateMany()`` method to update multiple documents.
64+
65+
A Note About _id
66+
~~~~~~~~~~~~~~~~~
6167

6268
Each document in a MongoDB collection has a unique and immutable ``_id``
6369
field. You cannot use update operations to change the
6470
``_id`` field. If you attempt to change this field, the update
6571
methods return a ``WriteError``.
6672

67-
.. _golang-update-documents:
68-
69-
Update
70-
------
71-
72-
Use the ``UpdateOne()`` or ``UpdateByID()`` method to update a single
73-
document.
74-
75-
Use the ``UpdateMany()`` method to update multiple documents.
76-
7773
.. _golang-update-document:
7874

7975
Parameters
80-
~~~~~~~~~~
76+
----------
8177

8278
Each method takes an **update document** that includes at least one **update operator**.
8379
The update operator specifies the type of update to perform. The update
@@ -110,7 +106,7 @@ and descriptions </reference/operator/update-field/>`.
110106
</tutorial/update-documents-with-aggregation-pipeline/>`.
111107

112108
Return Values
113-
~~~~~~~~~~~~~
109+
-------------
114110

115111
``UpdateOne()``, ``UpdateByID()``, and ``UpdateMany()`` return an
116112
``UpdateResult`` type that contains information about the update
@@ -145,7 +141,7 @@ See our :ref:`upsert guide <golang-upsert-guide>`
145141
to learn how to insert a new document if no documents match the query filter.
146142

147143
UpdateOne() Example
148-
~~~~~~~~~~~~~~~~~~~
144+
-------------------
149145

150146
The following document describes an employee:
151147

@@ -204,7 +200,7 @@ The following shows the updated document resulting from the preceding update ope
204200
}
205201

206202
UpdateMany() Example
207-
~~~~~~~~~~~~~~~~~~~~
203+
--------------------
208204

209205
The following example uses the ``listingsAndReviews`` collection in the
210206
``sample_airbnb`` dataset from the :atlas:`Atlas sample datasets </sample-data>`.
@@ -213,13 +209,25 @@ The example performs the following on the ``listingsAndReviews`` collection:
213209
- Matches documents in which the market field of the address subdocument, ``address.market`` is "Sydney"
214210
- Updates the ``price`` in the matched documents by 1.15 times
215211

216-
.. literalinclude:: /includes/usage-examples/code-snippets/updateMany.go
217-
:start-after: begin updatemany
218-
:end-before: end updatemany
219-
:emphasize-lines: 9
220-
:language: go
221-
:copyable:
222-
:dedent:
212+
.. io-code-block::
213+
:copyable: true
214+
215+
.. input::
216+
:language: go
217+
218+
.. literalinclude:: /includes/usage-examples/code-snippets/updateMany.go
219+
:start-after: begin updatemany
220+
:end-before: end updatemany
221+
:emphasize-lines: 9
222+
:language: go
223+
:copyable:
224+
:dedent:
225+
226+
.. output::
227+
:language: none
228+
:visible: false
229+
230+
Documents updated: 609
223231

224232
After you run the example, you can find the following updated
225233
documents in the ``listingsAndReviews`` collection:

0 commit comments

Comments
 (0)