Skip to content

DOCSP-35977: Find multiple usage example #2833

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

DOCSP-35977: Find multiple usage example #2833

merged 19 commits into from
Apr 22, 2024

Conversation

norareidy
Copy link
Contributor

@norareidy norareidy commented Apr 8, 2024

Adds a usage example showing how to retrieve multiple documents.
JIRA - https://jira.mongodb.org/browse/DOCSP-35977
Staging -
https://preview-mongodbcchomongodb.gatsbyjs.io/laravel/DOCSP-35977-ccho/usage-examples/find/

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 few questions and suggestions!

Comment on lines 56 to 69
// Results are truncated

{
"_id": "...",
"plot": "The economic and cultural growth of Colorado spanning two centuries from the mid-1700s to the late-1970s.",
"genres": [
"Action",
"Adventure",
"Drama"
],
"runtime": 1256,
...
"title": "Centennial",
...
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 showing the expanded "title", "runtime", and "_id" fields could make the output easier to read and would be sufficient to help the reader understand the query filter and sort order. I think the rest could be hidden with "..."

Perhaps you'd want matches that also aren't easy to mistake for
another more popular title such as "Taken" since the "runtime" field could be a point of confusion.

Another solution could be to avoid using the "_id" sort and instead using the "runtime" value so that you could omit the "_id" field.

.. tip::

To learn more about retrieving documents with {+odm-short+}, see the
:ref:`laravel-fundamentals-retrieve` guide
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
:ref:`laravel-fundamentals-retrieve` guide
:ref:`laravel-fundamentals-retrieve` guide.


.. tip::

To learn more about retrieving documents with {+odm-short+}, see the
Copy link
Contributor

Choose a reason for hiding this comment

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

I think "where()" is one of many methods you can chain to the model class. Maybe this sentence could be modified to indicate there are other ways of retrieving documents.

"To learn about other ways to retrieve documents..."

- Uses the ``Movie`` Eloquent model to represent the ``movies`` collection in the
``sample_mflix`` database
- Retrieves 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.

Suggestion:
The example shows code to print out the retrieved documents, so I think it should either be mentioned or the code should be omitted.


// end-find

$this->assertInstanceOf(Movie::class, $movie);
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 $movie hasn't been declared, so I would omit this assertion, or place it in a loop similar to lines 27-29.

Comment on lines 23 to 26
Pass a query filter to the ``where()`` method to retrieve documents that meet a
set of criteria. MongoDB returns the matching documents according to their
:term:`natural order` in the database or according to the sort order that you can specify
by using the ``orderBy()`` method.
Copy link
Contributor

Choose a reason for hiding this comment

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

Question:
Can you access the cursor by chaining the "cursor()" method like this? If that's the preferred method of retrieving multiple results, I think we should show that.

@norareidy norareidy marked this pull request as ready for review April 9, 2024 15:22
@norareidy norareidy requested a review from a team as a code owner April 9, 2024 15:22
@norareidy norareidy requested a review from GromNaN April 9, 2024 15:22
@norareidy norareidy requested a review from a team as a code owner April 17, 2024 19:41
@ccho-mongodb ccho-mongodb requested a review from GromNaN April 19, 2024 04:55
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.

],
[
'title' => 'Basketball',
'runtime' => 600,
Copy link
Member

Choose a reason for hiding this comment

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

I've added an item with runtime <= 900 for the test to be complete.

@norareidy norareidy merged commit 6ac2b6a into mongodb:4.1 Apr 22, 2024
@norareidy norareidy deleted the DOCSP-35977-find-multiple-usage branch April 22, 2024 18:53
This was referenced Apr 22, 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