@@ -20,10 +20,10 @@ Replace Documents
20
20
Overview
21
21
--------
22
22
23
- In this guide, you can learn how to use the {+library-short +} to perform a replace
24
- operation on a document in a MongoDB collection. A replace operation performs
25
- differently than an update operation. An update operation modifies only the
26
- specified fields in a target document. A replace operation removes *all* fields
23
+ In this guide, you can learn how to use the {+php-library +} to run a replace
24
+ operation on MongoDB collection. A replace operation performs differently
25
+ than an update operation. An update operation modifies only the specified
26
+ fields in a target document. A replace operation removes *all* fields
27
27
in the target document and replaces them with new ones.
28
28
29
29
To replace a document, use the ``MongoDB\Collection::replaceOne()`` method.
@@ -98,18 +98,17 @@ methods:
98
98
* - ``isAcknowledged()``
99
99
- | Returns a boolean indicating whether the write operation was acknowledged.
100
100
101
-
102
-
103
101
Example
104
102
~~~~~~~
105
103
106
104
The following example uses the ``replaceOne()`` method to replace the fields and values
107
- of a document in which the ``name`` field value is ``'Pizza Town'``:
105
+ of a document in which the ``name`` field value is ``'Pizza Town'``. It then prints
106
+ the number of modified documents:
108
107
109
108
.. io-code-block::
110
109
:copyable:
111
110
112
- .. input:: /includes/write/update .php
111
+ .. input:: /includes/write/replace .php
113
112
:start-after: start-replace-one
114
113
:end-before: end-replace-one
115
114
:language: php
@@ -179,11 +178,14 @@ table describes some options you can set in the array:
179
178
fields </reference/command/insert/#command-fields>` guide in the
180
179
{+mdb-server+} manual.
181
180
181
+ Example
182
+ ~~~~~~~
183
+
182
184
The following code uses the ``replaceOne()`` method to find the first document
183
185
in which the ``name`` field has the value ``'Food Town'``, then replaces this document
184
186
with a new document in which the ``name`` value is ``'Food World'``. Because the
185
187
``upsert`` option is set to ``true``, the library inserts a new document if the query
186
- filter doesn't match any existing documents.
188
+ filter doesn't match any existing documents:
187
189
188
190
.. literalinclude:: /includes/write/replace.php
189
191
:start-after: start-replace-options
@@ -204,5 +206,5 @@ API Documentation
204
206
To learn more about any of the methods or types discussed in this
205
207
guide, see the following API documentation:
206
208
207
- - `MongoDB\\Collection::replaceOne() <{+api+}/reference/ method/MongoDBCollection-replaceOne/>`__
208
- - `MongoDB\\UpdateResult <{+api+}/reference/ class/MongoDBUpdateResult/>`__
209
+ - `MongoDB\\Collection::replaceOne() <{+api+}/method/MongoDBCollection-replaceOne/>`__
210
+ - `MongoDB\\UpdateResult <{+api+}/class/MongoDBUpdateResult/>`__
0 commit comments