-
Notifications
You must be signed in to change notification settings - Fork 1.5k
DOCSP-35974: Update one usage example #2781
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
norareidy
merged 31 commits into
mongodb:4.1
from
norareidy:DOCSP-35974-update-one-usage-ex
Apr 3, 2024
Merged
Changes from 12 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
2a01a1f
DOCSP-35974: Update one usage example
norareidy 5d5bc52
fixes
norareidy de2fb19
other usage ex changes
norareidy 0f0479c
reworking the example
norareidy 6edf281
add tip, spacing
norareidy 8bcf1a7
restructuring
norareidy a1238b0
reword tip
norareidy 30be915
fixes
norareidy 3f9ef3d
edits
norareidy 82a4f20
reword
norareidy 74db7ef
add more running info
norareidy c9e279c
small change
norareidy ae4bb21
edits
norareidy 5ceb6b3
source constant
norareidy 97187cd
test file
norareidy d9aa3c1
move test file
norareidy 0008e18
single quotes
norareidy cb10358
print syntax
norareidy 6c3d851
print statement again
norareidy 71f72e7
Merge remote-tracking branch 'upstream/4.1' into DOCSP-35974-update-o…
norareidy f3ac9c8
JT feedback
norareidy b237a86
apply phpcbf formatting
norareidy 4856810
code
norareidy 777e3cb
code fix
norareidy d67827a
apply phpcbf formatting
norareidy abab190
JT feedback
norareidy d7b03f1
Merge branch 'DOCSP-35974-update-one-usage-ex' of github.com:norareid…
norareidy aabaf2c
Merge remote-tracking branch 'upstream/4.1' into pr/2781
GromNaN 2fb18a5
Fix UpdateOneTest example
GromNaN 3f9e394
Merge remote-tracking branch 'upstream/4.1' into DOCSP-35974-update-o…
norareidy 1c90a28
add to TOC
norareidy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
.. _laravel-update-one-usage: | ||
|
||
================= | ||
Update a Document | ||
================= | ||
|
||
.. facet:: | ||
:name: genre | ||
:values: reference | ||
|
||
.. meta:: | ||
:keywords: update one, modify, code example | ||
|
||
.. contents:: On this page | ||
:local: | ||
:backlinks: none | ||
:depth: 1 | ||
:class: singlecol | ||
|
||
You can update a document in a collection by retrieving a single document and calling | ||
the ``update()`` method on an Eloquent model or a query builder. | ||
|
||
Pass a query filter to the ``where()`` method, sort the matching documents, and call the | ||
``first()`` method to match only one document. Then, update this matching document by passing | ||
GromNaN marked this conversation as resolved.
Show resolved
Hide resolved
|
||
your intended document changes to the ``update()`` method. | ||
|
||
Example | ||
------- | ||
|
||
This usage example performs the following actions: | ||
|
||
- Uses the ``Movie`` Eloquent model to represent the ``movies`` collection in the | ||
``sample_mflix`` database. | ||
- Updates a document from the ``movies`` collection that matches a query filter. | ||
|
||
The example calls the following methods on the ``Movie`` model: | ||
|
||
- ``where()``: matches documents in which the value of the ``title`` field is ``'Carol'``. | ||
- ``orderBy()``: sorts matched documents by their ascending ``_id`` values. | ||
- ``first()``: retrieves only the first matching document. | ||
- ``update()``: updates the value of the ``imdb.rating`` nested field to from ``6.9`` to | ||
``7.3``. This method also updates the ``imdb.votes`` nested field from ``493`` to ``142000``. | ||
|
||
.. io-code-block:: | ||
:copyable: true | ||
|
||
.. input:: | ||
:language: php | ||
|
||
$movie = Movie::where('title', 'Carol') | ||
->orderBy('_id') | ||
->first() | ||
->update([ | ||
"imdb" => [ | ||
"rating" => 7.3, | ||
"votes" => 142000 | ||
], | ||
]); | ||
|
||
.. output:: | ||
:language: console | ||
:visible: false | ||
|
||
1 | ||
|
||
The expected output shows the number of modified documents. To view the output, add the operation | ||
to a controller endpoint. Then, create a web route that calls the controller endpoint and returns | ||
the result to a web interface. | ||
|
||
.. tip:: | ||
|
||
You can add this usage example to the Laravel application created in the :ref:`laravel-quick-start` | ||
and view the expected output. For instructions on editing your ``{+quickstart-app-name+}`` application | ||
to run the usage example, see the :ref:`Usage Example landing page <laravel-usage-examples>`. | ||
|
||
To learn more about updating data with {+odm-short+}, see the `Updates | ||
<https://laravel.com/docs/6.x/eloquent#updates>`__ section of the Laravel documentation. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.