@@ -3,3 +3,53 @@ Replace a Document
3
3
==================
4
4
5
5
.. default-domain:: mongodb
6
+
7
+ You can replace a document in a collection by using the ``ReplaceOne()``
8
+ method.
9
+
10
+ The following example specifies a query filter and replacement document
11
+ to the ``ReplaceOne()`` method, which matches a document in the
12
+ ``haikus`` collection where the ``title`` field is "Record of a
13
+ Shriveled Datum" and replaces it with a document that contains a
14
+ ``title`` and ``text`` field about a haiku:
15
+
16
+ .. include:: /includes/usage-examples/run-example-tip.rst
17
+
18
+ .. literalinclude:: /includes/usage-examples/code-snippets/replace.go
19
+ :start-after: begin replace
20
+ :end-before: end replace
21
+ :emphasize-lines: 5
22
+ :language: go
23
+ :dedent:
24
+
25
+ Click `here <{+example+}/replace.go>`__ to see a fully runnable example.
26
+
27
+ Expected Result
28
+ ---------------
29
+
30
+ After you run the preceding code snippet, you should be able to find the
31
+ replacement document in the ``haikus`` collection:
32
+
33
+ .. code-block:: json
34
+ :copyable: false
35
+
36
+ {
37
+ "_id" : ObjectId("..."),
38
+ "title" : "Dodging Greys",
39
+ "text" : "When there're no matches, no longer need to panic. You can use upsert."
40
+ }
41
+
42
+ For an example on how to find a document, see our :doc:`Find
43
+ One Usage Example </usage-examples/findOne>`.
44
+
45
+ Additional Information
46
+ ----------------------
47
+
48
+ For more information on replacing documents, specifying query filters, and
49
+ handling potential errors, see our guide on **<TODO: change a document
50
+ fundamental page>**.
51
+
52
+ API Documentation
53
+ ~~~~~~~~~~~~~~~~~
54
+
55
+ `ReplaceOne() <{+godocs+}/mongo#Collection.ReplaceOne>`__
0 commit comments