Skip to content

DOCSP-35975: Update many usage example #2836

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
merged 6 commits into from
Apr 19, 2024
Merged

DOCSP-35975: Update many usage example #2836

merged 6 commits into from
Apr 19, 2024

Conversation

norareidy
Copy link
Contributor

@norareidy norareidy commented Apr 9, 2024

Adds a usage example showing how to update multiple documents
JIRA - https://jira.mongodb.org/browse/DOCSP-35975
Staging - https://preview-mongodbnorareidy.gatsbyjs.io/laravel/DOCSP-35975/usage-examples/updateMany/

Checklist

  • Add tests and ensure they pass
  • Add an entry to the CHANGELOG.md file
  • Update documentation for new features

Copy link
Contributor

@ccho-mongodb ccho-mongodb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, a couple questions and suggestions!

:class: singlecol

You can update multiple documents in a collection by calling the ``update()`` method
on an Eloquent model or query builder.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question:
Is it possible to call on the model directly? I could be wrong, but I think you need to chain it to an object collection like the result of "where()" for Laravel MongoDB.

I think this description should match what's shown in the example either way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, it needs to be on an object collection - fixed

Comment on lines +32 to +34
- Uses the ``Movie`` Eloquent model to represent the ``movies`` collection in the
``sample_mflix`` database
- Updates documents from the ``movies`` collection that match a query filter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to prior feedback, I think printing the output should be mentioned or the code that prints should be hidden.

Comment on lines 63 to 65
To learn more about updating data with {+odm-short+}, see the `Updates
<https://laravel.com/docs/{+laravel-docs-version+}/eloquent#updates>`__ section of the
Laravel documentation.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question:
Do you know if all the content in this section is available in Laravel MongoDB? For example, do the methods listed in the "Examining Attribute Changes" section work?

If these do not work, perhaps this link should be omitted.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They don't seem to work, so I'll remove

- ``where()``: matches documents in which the value of the ``imdb.rating`` nested field
is greater than ``9``
- ``update()``: updates the matching documents by adding an ``acclaimed`` field and setting
its value to ``true``
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion:
I think it could be helpful to add some information about the value printed even if it seems self-explanatory. E.g.
"The update() method returns the number of documents successfully updated"

@GromNaN GromNaN added the docs label Apr 10, 2024

.. tip::

To learn more about updating data with {+odm-short+}, see the :ref:`laravel-fundamentals-modify-documents`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: since this links to a section of the Write operations page, this PR will be merged after #2808

@norareidy norareidy marked this pull request as ready for review April 10, 2024 17:53
@norareidy norareidy requested a review from a team as a code owner April 10, 2024 17:53
@norareidy norareidy requested a review from GromNaN April 12, 2024 18:22
@norareidy norareidy requested a review from GromNaN April 17, 2024 19:08
Copy link
Member

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ccho-mongodb ccho-mongodb merged commit 26d9632 into mongodb:4.1 Apr 19, 2024
This was referenced Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants