-
Notifications
You must be signed in to change notification settings - Fork 1.5k
DOCSP-35966 query builder #2790
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
DOCSP-35966 query builder #2790
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.
Good work on this long page! Happy to discuss any of my comments
docs/query-builder.txt
Outdated
lets you write queries for any supported database by using the same fluent | ||
interface and syntax. |
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: What does "same" mean in this context?
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 I had "a common" previously to represent the "fluent interface and syntax" which might be more clear than "the same". Let me know if one is more clear than the other, or how you might otherwise word it.
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.
maybe you can just add "... the same ... as the Laravel query builder"?
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 that perspective!
I wanted to describe the query builder rather than comparing it with something else, but it seems like using noun phrases (e.g. #2790 (comment)) can cause some confusion.
In this sentence, the items being compared are syntax you use to access each of the supported databases rather than something with the query builder (given it's describing the query builder).
I'll spend a few minutes to try to reorder the sentence in a way that avoids connecting noun phrases to restrictive clauses.
docs/query-builder.txt
Outdated
lets you perform database operations. Facades are static interfaces to | ||
classes that make the syntax more concise, avoid runtime errors, and improve | ||
testability. |
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.
nit: ambiguous identifiers - do the classes made the syntax more concise, etc or the facades
docs/query-builder.txt
Outdated
**Where** | ||
{+odm-short+} aliases the ``DB`` method ``table()`` as the ``collection()`` | ||
method. Chain methods to specify the command and any constraints. Then, chain | ||
the ``get()`` method at the end to run them on the MongoDB collection. The |
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 ``get()`` method at the end to run them on the MongoDB collection. The | |
the ``get()`` method at the end to run the command on the MongoDB collection. The |
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 spotting this! I'll reword since "them" refers to the unspecified number of chained methods.
docs/query-builder.txt
Outdated
Post::where('votes', '>', 0) | ||
->orWhere('is_approved', true) | ||
->get(); | ||
This guide shows examples of the following types of query builder 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.
This guide shows examples of the following types of query builder operations: | |
This guide provides examples for the following types of query builder 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.
I considered the suggestion while, but think that "for" might not be the correct preposition. I think "for" would imply that the examples are being delivered to someone or something. I'll use "provides" and pair it with "of".
docs/query-builder.txt
Outdated
The following example shows how to use the ``near`` query operator | ||
with the ``where()`` query builder method to match documents that contain the | ||
field ``random_review``: |
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; description does not match
|
||
**Push** | ||
MongoDB Write 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.
S: add introduction to section list
docs/query-builder.txt
Outdated
|
||
If you **DON'T** want duplicate items, set the third parameter to ``true``: | ||
The following example shows how to use the ``increment()`` | ||
query builder method to add "3000" to the value of |
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.
query builder method to add "3000" to the value of | |
query builder method to add ``3000`` to the value of |
docs/query-builder.txt
Outdated
'message' => 'Hi John', | ||
]); | ||
The following example shows how to use the ``push()`` query builder method to | ||
add "``Gary Cole``" to the ``cast`` array field in the matched document: |
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.
add "``Gary Cole``" to the ``cast`` array field in the matched document: | |
add ``"Gary Cole"`` to the ``cast`` array field in the matched document: |
docs/query-builder.txt
Outdated
|
||
.. code-block:: php | ||
The following example shows how to use the ``pull()`` query builder method | ||
to remove the "``Adventure``" value from the ``genres`` field from the document |
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.
to remove the "``Adventure``" value from the ``genres`` field from the document | |
to remove the ``"Adventure"`` value from the ``genres`` field from the document |
@rustagir thanks for the review. I think I addressed everything and went through the content multiple times. I also moved all the code snippets to a new unit test file. |
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 with some small fixes
- :ref:`laravel-retrieve-query-builder` | ||
- :ref:`laravel-modify-results-query-builder` | ||
- :ref:`laravel-mongodb-read-query-builder` | ||
- :ref:`laravel-mongodb-write-query-builder` |
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: Make the titles of the subsections all in the same form (action oriented)
docs/query-builder.txt
Outdated
The following example shows how to use the ``where()`` query | ||
builder method to retrieve documents from the ``movies`` collection | ||
that contain an ``imdb.votes`` field value of ``350``. Click the | ||
:guilabel:`{+code-output-label+}` button to see the results returned | ||
by the query: | ||
|
||
.. io-code-block:: | ||
:copyable: true | ||
|
||
.. input:: /includes/query-builder/QueryBuilderTest.php | ||
:language: php | ||
:dedent: | ||
:start-after: begin query where | ||
:end-before: end query where |
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: description does not match example
imdb.votes field value of 350
where('imdb.rating', 9.3)
docs/query-builder.txt
Outdated
The following example shows how to chain the ``orWhere()`` | ||
query builder method to retrieve documents from the | ||
``movies`` collection that either match the ``year`` | ||
value of ``1955`` or match the title ``"Back to the Future"``: |
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.
value of ``1955`` or match the title ``"Back to the Future"``: | |
value of ``1955`` or match the ``title`` value ``"Back to the Future"``: |
docs/query-builder.txt
Outdated
The following example shows how to use the ``whereIn()`` | ||
query builder method to retrieve documents from the | ||
``movies`` collection that match at least one of the | ||
``title`` values in the specified set. |
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.
``title`` values in the specified set. | |
``title`` values in the specified set: |
docs/query-builder.txt
Outdated
The following example shows how to use the ``whereNull()`` | ||
query builder method to retrieve documents from the | ||
``movies`` collection that omit a ``runtime`` value | ||
or field. |
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.
or field. | |
or field: |
wildcard characters: | ||
|
||
- ``%`` which matches zero or more characters | ||
- ``_`` which matches a single character |
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: if the _
matches a single character, why is Spider Woman in the results?
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: if the
_
matches a single character, why is Spider Woman in the results?
Good question -- whitespace is a character in the context of SQL queries. The Laravel documentation omits any explanation of the wildcard characters that they use, but I thought it would be good to reiterate the SQL LIKE syntax.
Let me know if you think this needs further explanation.
docs/query-builder.txt
Outdated
The following example shows how to pass the ``mod`` | ||
query operator with the ``where()`` query builder | ||
method to match documents by using the expression | ||
``"year % 2 == 0"``, which matches even values for |
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: remove quotes from the expression
``"year % 2 == 0"``, which matches even values for | |
``year % 2 == 0``, which matches even values for |
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 updated the tests to add assertions, using a subset of the data.
The following example shows how to use the ``near`` query operator | ||
with the ``where()`` query builder method to match documents that | ||
contain a location that is up to ``50`` meters from a GeoJSON Point | ||
object: |
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.
This should tell how to create a geo index.
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.
Will do -- I can link to the Schema Builder section "Create a Geospatial Index". However, I'll need to merge in the 4.1 branch to get that content. Is that ok or should I create a separate ticket to address this?
JIRA: https://jira.mongodb.org/browse/DOCSP-35966
Staging: https://preview-mongodbcchomongodb.gatsbyjs.io/laravel/DOCSP-35966-query-builder/query-builder/
Checklist