Skip to content

Commit ab8fbc7

Browse files
committed
trivial: tweak update example for combined multi and upsert
1 parent ec390f8 commit ab8fbc7

File tree

1 file changed

+25
-49
lines changed

1 file changed

+25
-49
lines changed

source/reference/method/db.collection.update.txt

Lines changed: 25 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -461,63 +461,39 @@ Given a ``books`` collection that includes the following documents:
461461

462462
.. code-block:: javascript
463463

464-
{
465-
"_id" : 11,
466-
"author" : "Dante",
467-
"item" : "Divine Comedy",
468-
"price" : 18 }
469-
{
470-
"_id" : 22,
471-
"author" : "Dante",
472-
"item" : "The Banquet",
473-
"price" : 19 }
474-
{
475-
"_id" : 33,
476-
"author" : "Dante",
477-
"item" : "Monarchia",
478-
"price" : 14
479-
}
480-
481-
The following command uses the ``multi`` parameter to update all
482-
documents where ``author`` is ``"Dante"`` and uses the *upsert*
483-
parameter to create a new document if no such documents are found
464+
{ _id: 11, author: "Dante", item: "Divine Comedy", price: 18, translatedBy: "abc123" }
465+
{ _id: 12, author: "Dante", item: "Divine Comedy", price: 21, translatedBy: "jkl123" }
466+
{ _id: 13, author: "Dante", item: "Divine Comedy", price: 15, translatedBy: "xyz123" }
467+
468+
The following command specifies the ``multi`` parameter to update all
469+
documents where ``item`` is ``"Divine Comedy"`` and the ``author`` is
470+
``"Dante"`` and specifies the ``upsert`` parameter to create a new
471+
document if no matching documents are found
484472
[#previous-versions-upsert-multi]_:
485473

486474
.. code-block:: javascript
487475

488-
db.books.update( { author: "Dante" },
489-
{ $set: { born: "Florence", died: "Ravenna" } },
490-
{ upsert: true, multi: true }
491-
)
476+
db.books.update(
477+
{ item: "Divine Comedy", author: "Dante" },
478+
{ $set: { reorder: false, price: 10 } },
479+
{ upsert: true, multi: true }
480+
)
492481

493-
The operation results in the following:
482+
The operation updates all three matching documents and results in the
483+
following:
494484

495485
.. code-block:: javascript
496486

497-
{
498-
"_id" : 11,
499-
"author" : "Dante",
500-
"born" : "Florence",
501-
"died" : "Ravenna",
502-
"item" : "Divine Comedy",
503-
"price" : 18
504-
}
505-
{
506-
"_id" : 22,
507-
"author" : "Dante",
508-
"born" : "Florence",
509-
"died" : "Ravenna",
510-
"item" : "The Banquet",
511-
"price" : 19
512-
}
513-
{
514-
"_id" : 33,
515-
"author" : "Dante",
516-
"born" : "Florence",
517-
"died" : "Ravenna",
518-
"item" : "Monarchia",
519-
"price" : 14
520-
}
487+
{ _id: 11, author: "Dante", item: "Divine Comedy", price: 10, reorder: false, translatedBy: "abc123" }
488+
{ _id: 12, author: "Dante", item: "Divine Comedy", price: 10, reorder: false, translatedBy: "jkl123" }
489+
{ _id: 13, author: "Dante", item: "Divine Comedy", price: 10, reorder: false, translatedBy: "xyz123" }
490+
491+
If the collection had *no* matching document, the operation would
492+
result in the insertion of a document:
493+
494+
.. code-block:: javascript
495+
496+
{ _id: ObjectId("536aa66422363a21bc16bfd7"), author: "Dante", item: "Divine Comedy", reorder: false, price: 10 }
521497

522498
.. [#previous-versions-upsert-multi]
523499
.. include:: /includes/fact-upsert-multi-options.rst

0 commit comments

Comments
 (0)