@@ -3,3 +3,56 @@ Update a Document
33=================
44
55.. default-domain:: mongodb
6+
7+ You can update a document in a collection by using the ``UpdateOne()``
8+ method.
9+
10+ The following example passes a query filter and an update parameter to the
11+ ``UpdateOne()`` method, which matches a document in the ``restaurants`` collection
12+ by the value of its ``_id`` field and creates a new field in that document called
13+ ``avg_rating`` with a value of *4.4*:
14+
15+ .. include:: /includes/run-example-tip.rst
16+
17+ .. literalinclude:: /code-snippets/updateOne.go
18+ :start-after: begin updateone
19+ :end-before: end updateone
20+ :emphasize-lines: 6
21+ :language: go
22+ :dedent:
23+
24+ Click here **<TODO: github link to file>** to see a fully runnable example.
25+
26+ Expected Result
27+ ---------------
28+
29+ After you run the code example, the document will include the
30+ ``avg_rating`` field with the specified value:
31+
32+ .. code-block:: json
33+ :copyable: false
34+
35+ // result truncated
36+ {
37+ "_id" : ObjectId("5eb3d668b31de5d588f42a7a"),
38+ ...
39+ "name" : "Green House Cafe",
40+ "restaurant_id" : "40372112",
41+ "avg_rating" : 4.4
42+ }
43+
44+ Additional Information
45+ ----------------------
46+
47+ For more information on updating documents, specifying query filters, and
48+ handling potential errors, see our guide on **<TODO: change a document
49+ fundamental page>**.
50+
51+ For more information on update operators,
52+ see the :manual:`MongoDB update operator reference documentation
53+ </reference/operator/update/#update-operators>`.
54+
55+ API Documentation
56+ ~~~~~~~~~~~~~~~~~
57+
58+ `UpdateOne() <https://pkg.go.dev/go.mongodb.org/
[email protected] /mongo#Collection.UpdateOne>`_
0 commit comments