-
Notifications
You must be signed in to change notification settings - Fork 1.5k
DOCSP-35957: Retrieve guide #2722
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a few small things + questions
docs/retrieve.txt
Outdated
-------- | ||
|
||
In this guide, you can learn how to retrieve data from your MongoDB | ||
collections using **find operations**. Find operations are commands that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
collections using **find operations**. Find operations are commands that | |
collections by using **find operations**. Find operations are commands that |
docs/retrieve.txt
Outdated
Pass the field name and value for which you are querying as parameters to ``where()``. | ||
|
||
You can also pass a comparison operator as the ``where()`` method's second parameter, | ||
such as the ``>`` operator. If you do not include a comparison operator parameter, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S: explain what >
does
such as the ``>`` operator. If you do not include a comparison operator parameter, | |
such as the ``>`` operator to perform a "greater than" comparison. If you do not include a comparison operator parameter, |
docs/retrieve.txt
Outdated
.. input:: | ||
:language: php | ||
|
||
$movies = Movie::all(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: does this code example also print the retrieved documents?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code snippet itself doesn't, but editing the view class according to the Quick Start instructions outputs the results in the format shown
docs/retrieve.txt
Outdated
$movies = | ||
Movie::where('year', 2010) | ||
->where('imdb.rating', '>', 8.5) | ||
->get(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: same question here - does this code actually print the results?
docs/retrieve.txt
Outdated
The following example returns one document in which the value of the ``title`` field | ||
is ``"The Parent Trap"``: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S: could you use an example here for a query that would definitely match more than one document to show that the method matches only the first one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used "The Parent Trap" because there are two versions (the original and the remake) and two matching documents - would it be better to have a query that's even more broad / matches more documents?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a query filter such as "year == 1961" or "runtime == 30" could provide a stronger hint that there's more than one result (without risk of causing an overload of results since the limit function hasn't been introduced).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed!
docs/retrieve.txt
Outdated
- Controller class to store and run the find operations | ||
- View class to display the results of the find operations | ||
|
||
For instructions on creating these classes, see the Quick Start. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion:
I think it would be good to add explanations or links to instructions on how to edit the files and view the results. I think the instructions could eventually be moved to a "Fundamentals" landing page. Happy to help with the content for this.
docs/retrieve.txt
Outdated
To retrieve one document that matches a set of criteria, use the ``where()`` method | ||
followed by the ``first()`` method. | ||
|
||
For more information about the ``where()`` method and its parameters, see the | ||
:ref:`laravel-find-all` section of this guide. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion:
I think it would be helpful to mention sorting, even if showing how to sort is not shown on this page so that the reader can understand, from a set of results, which document to expect as the "first".
docs/retrieve.txt
Outdated
Find All Documents | ||
------------------ | ||
|
||
To retrieve all documents in a collection, use the ``all()`` method. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue:
I think "use the ___ method" might not be clear as to what you're calling it on.
Suggestion:
I think it could be helpful to make the following changes:
- Describe connection between "MongoDB collection" and "Laravel Model" in the Overview section.
- Provide specifics on what the user should call the "all()" method on.
docs/retrieve.txt
Outdated
.. input:: | ||
:language: php | ||
|
||
$movies = Movie::all(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue:
This relates to both "Find All Documents in a Collection Example" and "Find All Matching Documents Example".
I ran an issue retrieving large result sets in the Quick Start because the movies collection is large and the web app will time out trying to retrieve them. If it was able to retrieve them, displaying them on a webpage would probably cause memory issues for the browser.
Suggestion:
I think omitting the example could prevent users from running into the same issue. Instead of showing the example, describe the syntax of the method and alias and what it would do.
Instead of showing output, I think it would be better just to show the syntax of how to provide an empty filter (Movie::get()
), which would help them understand how to chain other modifiers, and its alias (Movie::all()
). Rather than showing the result sets, it would be helpful to add an admonition mentioning that sample sets such as the movies collection would be too large.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a few things!
docs/retrieve.txt
Outdated
In this guide, you can learn how to retrieve data from your MongoDB | ||
collections by using **find operations**. Find operations are commands that | ||
retrieve documents from the server. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S: these sentences kind of go in circles. The first sentence says that you you can retrieve data by using find operations -> find operations retrieve data. I noticed this is the wording used on our other pages too.. I think you can use the phrase "find operations" first.
What about something like:
In this guide, you can learn how to retrieve data from your MongoDB | |
collections by using **find operations**. Find operations are commands that | |
retrieve documents from the server. | |
In this guide, you can learn how to use the Laravel package to perform find operations on your | |
MongoDB collections. Find operations allow you to retrieve documents based on criteria that you specify. |
docs/retrieve.txt
Outdated
- :ref:`laravel-retrieve-setup` | ||
- :ref:`laravel-retrieve-matching` | ||
- :ref:`laravel-modify-find` | ||
- :ref:`laravel-addtl-info` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S: add some description to these sections like here
docs/retrieve.txt
Outdated
.. warning:: | ||
|
||
The ``movies`` collection in the Atlas sample dataset stores a large amount of data. | ||
Retrieving and displaying all documents in this collection may cause your web | ||
application to time out. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.. warning:: | |
The ``movies`` collection in the Atlas sample dataset stores a large amount of data. | |
Retrieving and displaying all documents in this collection may cause your web | |
application to time out. | |
.. warning:: | |
The ``movies`` collection in the Atlas sample dataset stores a large amount of data. | |
Retrieving and displaying all documents in this collection might cause your web | |
application to time out. |
docs/retrieve.txt
Outdated
To learn more about sorting, see the following resources: | ||
|
||
- :manual:`Natural order </reference/glossary/#std-term-natural-order>` | ||
in the Server manual glossary | ||
- `Ordering, Grouping, Limit and Offset | ||
<https://laravel.com/docs/10.x/queries#ordering-grouping-limit-and-offset>`__ in the Laravel | ||
documentation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S: move into tip at the end of this section
docs/retrieve.txt
Outdated
The following example returns one document in which the value of the ``title`` field | ||
is ``"The Parent Trap"``: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed!
docs/retrieve.txt
Outdated
.. important:: Required File Changes | ||
|
||
To run the preceding code example, you must edit the ``MovieController.php`` file in your | ||
``my-app`` application. Copy the code example and paste it into the ``show()`` function, replacing | ||
any existing code inside this function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S: similar to earlier comment, move up
docs/retrieve.txt
Outdated
Use Laravel Queries to Retrieve Documents | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
Rather than on a model, you can run find operations on a query builder instance that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S: the first clause is a bit confusing
Rather than on a model, you can run find operations on a query builder instance that | |
You can run find operations on a query builder instance that represents your collection instead of running them on models. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for picking up this prototype page. After going through the staged content, I think the information could be easier to find with descriptive headings that don't overlap and separating out "how to run this" the into tabs.
I think the introductory sentences in each section could guide the readers better if they followed a consistent structure. Let me know if the suggestions I provided make sense.
Finally, while I didn't leave any other comments on this, I think any resource/link mentioned must be accompanied by information that connects it to what the reader should learn, especially when the content of the linked page doesn't provide that specific guidance.
Let me know if you want to pair on changes!
docs/retrieve.txt
Outdated
|
||
You can pass the following types of query filters to the ``where()`` method: | ||
|
||
- ``where('<field name>', <value>)``: instructs MongoDB to return documents that match |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find it more explicit if the context of the function is provided. Otherwise they can think the function where
is global.
- ``where('<field name>', <value>)``: instructs MongoDB to return documents that match | |
- ``Model::where('<field name>', <value>)``: instructs MongoDB to return documents that match |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good, thanks for making all the changes! Most of the suggestions are straightforward, but let me know if there's anything you'd like to discuss and/or whether you want another review.
docs/retrieve.txt
Outdated
Overview | ||
-------- | ||
|
||
In this guide, you can learn how to use the Laravel package to perform **find operations** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion:
I think "Laravel MongoDB" (the odm-short source constant) could be more consistent with the product name:
In this guide, you can learn how to use the Laravel package to perform **find operations** | |
In this guide, you can learn how to use the {+odm-short+} to perform **find operations** |
docs/retrieve.txt
Outdated
Complete the :ref:`Quick Start <laravel-quick-start>` tutorial before running the examples in this | ||
guide. | ||
|
||
After completing the Quick Start, ensure that your MongoDB deployment and Laravel application | ||
satisfy the following requirements: | ||
|
||
- Your Atlas MongoDB deployment contains the Atlas sample data | ||
- ``Movie.php`` file contains a ``Movie`` model to represent the ``movies`` collection | ||
- ``MovieController.php`` file contains a ``show()`` function to run database operations | ||
- ``browse_movies.blade.php`` file contains HTML code to display the results of database | ||
operations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion:
I think the "Prerequisites" heading should describe a condition/state rather than provide instructions. One potential solution could be to replace the heading title with "Before You Get Started" and explain the following similar to this:
"To run the code in this guide, you need to complete the Quick Start tutorial, which includes setting up a MongoDB Atlas instance with sample data and the following files in your Laravel web application:
- Movie.php, which contains the Movie model that ...
"
docs/retrieve.txt
Outdated
|
||
Use the following syntax to specify the query: | ||
|
||
.. code-block:: go |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue:
I think "go" syntax highlighting might be compatible in this case, but it would be better to identify this as php code.
Suggestion:
I think using "php" would be more consistent.
Applies to all instances.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops didn't notice that - fixed!
docs/retrieve.txt
Outdated
to only return documents that meet these requirements. To run the query, call the ``where()`` | ||
method on an Eloquent model or query builder that represents your collection. | ||
|
||
You can pass the following types of query filters to the ``where()`` method: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion:
I think the description of the "types" in "types of query filters" is missing from the list items. I think describing the list items directly like the following would help guide the reader:
"You can use one of the following "where()" method calls to build a query:"
docs/retrieve.txt
Outdated
|
||
.. _laravel-retrieve-one: | ||
|
||
Retrieve Only One Result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion:
I think "Return the First Result" could be more descriptive since the section doesn't describe how to retrieve any other type of a single result (such as the last result).
Applies to the description contained in this section.
- ``skip()``: sets the number of documents to skip when returning results | ||
- ``take()``: sets the total number of documents to return | ||
- ``first()``: returns the first document that matches the query filter | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion:
I think the subheadings could be introduced, e.g.
"The following sections show examples of how to use these methods."
docs/retrieve.txt
Outdated
matching document according to the documents' natural order, or as they appear in the | ||
database. If you apply a sort to the find operation, ``first()`` returns the first matching | ||
document according to the sorted order. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion:
I think it would be better to recommend a consistent sort order before describing natural ordering.
E.g. "Use the sort() method when you use the first() to get consistent results when you query on a unique value. If you omit the sort() method, MongoDB returns the matching documents according to the documents' natural order."
docs/retrieve.txt
Outdated
|
||
Then, make the following changes to your Laravel Quick Start application: | ||
|
||
- Add the ``use Illuminate\Support\Facades\DB`` use statement to your ``MovieController.php`` |
There was a problem hiding this comment.
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 good to match this with the other mention of this import in the section description since both versions of the example use it. The other instance currently reads:
"import the DB facade into your controller file"
docs/retrieve.txt
Outdated
|
||
.. note:: | ||
|
||
This change is necessary because you cannot use the ``->`` object operator to access document fields when running |
There was a problem hiding this comment.
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 better if the admonition identified which change it refers to.
E.g.
"Since the Laravel query builder returns ... the view accesses the fields by using the ... syntax instead of the "->" object operator."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some small suggestions but LGTM! great work on this long PR!
docs/retrieve.txt
Outdated
tutorial. This tutorial provides instructions on setting up a MongoDB Atlas instance with | ||
sample data and creating the following files in your Laravel web application: | ||
|
||
- ``Movie.php`` file, which contains a ``Movie`` model to represent the ``movies`` collection |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- ``Movie.php`` file, which contains a ``Movie`` model to represent the ``movies`` collection | |
- ``Movie.php`` file, which contains a ``Movie`` model to represent documents in the ``movies`` collection |
docs/retrieve.txt
Outdated
operations | ||
|
||
The following sections describe how to edit the files in your Laravel application to run | ||
the code examples and view the expected output. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the code examples and view the expected output. | |
the find operation code examples and view the expected output. |
docs/retrieve.txt
Outdated
|
||
Chain the ``orderBy()`` method to ``first()`` to get consistent results when you query on a unique | ||
value. If you omit the ``orderBy()`` method, MongoDB returns the matching documents according to | ||
the documents' natural order, or as they appear in the database. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the documents' natural order, or as they appear in the database. | |
the documents' natural order, or as they appear in the collection. |
docs/retrieve.txt
Outdated
This example returns one document in which the value of the ``runtime`` field | ||
is ``30``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S: also describe that this code orders by _id
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM after a small fix
docs/retrieve.txt
Outdated
|
||
Use the following syntax to specify the query: | ||
|
||
.. code-block:: go |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.. code-block:: go | |
.. code-block:: php |
Thank you @norareidy |
Adds a find operations page to the docs.
JIRA: https://jira.mongodb.org/browse/DOCSP-35957
Staging: https://preview-mongodbnorareidy.gatsbyjs.io/laravel/DOCSP-35957/retrieve/
Checklist