Skip to content

DOCSP-35937 aggregations builder 4.3 #2876

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

Conversation

ccho-mongodb
Copy link
Contributor

JIRA: https://jira.mongodb.org/browse/DOCSP-35937

Staging:
https://preview-mongodbcchomongodb.gatsbyjs.io/laravel/DOCSP-35937-Aggregations-Builder-4.3/fundamentals/aggregation-builder/

Checklist

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

Chris Cho added 2 commits April 17, 2024 11:21
Copy link
Contributor

@rustagir rustagir left a comment

Choose a reason for hiding this comment

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

pretty much looks good, left a few comments/questions!

Comment on lines 28 to 29
An aggregation pipeline is a data processing pipeline that takes documents
as input, sequentially performs transformations and computations on the data,
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
An aggregation pipeline is a data processing pipeline that takes documents
as input, sequentially performs transformations and computations on the data,
An aggregation pipeline is a data processing pipeline that
sequentially performs transformations and computations on input data,

Comment on lines 72 to 73
This section features the following examples of common aggregation stages and
of an aggregation pipeline:
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
This section features the following examples of common aggregation stages and
of an aggregation pipeline:
This section features the following examples, which demonstrate how to use common
aggregation stages and combine stages to make an aggregation pipeline:

Comment on lines 247 to 249
This example stage performs a similar grouping to an equivalent
``distinct()`` query builder method. To learn more about the ``distinct()``
method, see the :ref:`laravel-distinct-usage` usage example.
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
This example stage performs a similar grouping to an equivalent
``distinct()`` query builder method. To learn more about the ``distinct()``
method, see the :ref:`laravel-distinct-usage` usage example.
This example stage performs a similar task as the
``distinct()`` query builder method. To learn more about the ``distinct()``
method, see the :ref:`laravel-distinct-usage` usage example.

You can chain the ``project()`` method to your aggregation pipeline to specify
which fields from the documents to display by this stage.

To specify fields to include, pass the name of a field and a truthy value,
Copy link
Contributor

Choose a reason for hiding this comment

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

Q: could including words like "truthy" and "falsy" confuse readers?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's a relatively common term and not obscure jargon. I provided examples in the qualifying phrase immediately after. Let me know if you had something else in mind for clarifying this.

Comment on lines 406 to 407
- Add the ``year`` field to the documents and set the value to the year
extracted from the ``birthday`` field.
Copy link
Contributor

Choose a reason for hiding this comment

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

S: could be more descriptive

Suggested change
- Add the ``year`` field to the documents and set the value to the year
extracted from the ``birthday`` field.
- Add the ``birth_year`` field to the documents and set the value to the year
extracted from the ``birthday`` field.

Copy link
Contributor

Choose a reason for hiding this comment

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

If you change this, change the year_avg field to birth_year_avg

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, will update the example to use birth_year and birth_year_avg field names.

Comment on lines 404 to 405
- Match all documents in the collection since the ``match()`` stage
is omitted.
Copy link
Contributor

Choose a reason for hiding this comment

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

Q: is this line necessary? It could be confusing to mention things that the pipeline does NOT include

Copy link
Contributor Author

@ccho-mongodb ccho-mongodb Apr 17, 2024

Choose a reason for hiding this comment

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

I thought it would be good to reinforce the information provided in the admonition in the Match Stage Example section. I think it is relevant to the description of what the pipeline does and might cause readers to question what documents are part of the pipeline if omitted.

Let me know if you think it would be better to omit it.

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 it could work better as a note, potentially, but I am ok with leaving as is too!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, will move it to an admonition.

@ccho-mongodb ccho-mongodb requested a review from rustagir April 17, 2024 16:51
Copy link
Contributor

@rustagir rustagir left a comment

Choose a reason for hiding this comment

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

lgtm with a few small suggestions, also happy to discuss my last comment


In this guide, you can learn how to perform aggregations and construct
pipelines by using the {+odm-short+} aggregation builder. The aggregation
builder lets you use a typesafe syntax to construct a MongoDB
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
builder lets you use a typesafe syntax to construct a MongoDB
builder lets you use a type-safe syntax to construct a MongoDB

Comment on lines 29 to 30
performs transformations and computations on input data, and outputs the
results as a new set of documents.
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
performs transformations and computations on input data, and outputs the
results as a new set of documents.
performs transformations and computations on input data, then outputs the
results as a new document or set of documents.

Comment on lines 32 to 34
An aggregation pipeline is composed of **aggregation stages**, which are
operators that process input data and output data that the next stage uses as
its input.
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
An aggregation pipeline is composed of **aggregation stages**, which are
operators that process input data and output data that the next stage uses as
its input.
An aggregation pipeline is composed of **aggregation stages**, which use
operators to process input data and produce data that the next stage uses as
its input.

Comment on lines 264 to 266
To specify an ascending sort, set the field value to the ``Sort::Asc`` enum.

To specify a descending sort, set the field value to the ``Sort::Desc`` enum.
Copy link
Contributor

Choose a reason for hiding this comment

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

S; combine into one sentence to shorten this section/reduce breaks

Comment on lines 404 to 405
- Match all documents in the collection since the ``match()`` stage
is omitted.
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 it could work better as a note, potentially, but I am ok with leaving as is too!

Comment on lines +457 to +458
The following function accepts the name of a field that contains a date
and returns an expression that extracts the year from the date:
Copy link
Contributor

Choose a reason for hiding this comment

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

S: I think this section should provide an example of a functionality that is not directly achievable from one aggregation operator, $year in this case. For example, could this example extract the year and add a fixed number to calculate something like the year they turned 18? Or a field to tell if they were born in the 20th century or 21st century or something like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks -- I think that's a great idea and I had thought of other ideas. However, I intentionally decided on something less complex to focus on documenting the custom operator factory usage.

@ccho-mongodb ccho-mongodb marked this pull request as ready for review April 17, 2024 18:06
@ccho-mongodb ccho-mongodb requested a review from a team as a code owner April 17, 2024 18:06
@ccho-mongodb ccho-mongodb requested a review from GromNaN April 17, 2024 18:06
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, with a suggestion.

**aggregation pipeline**.

An aggregation pipeline is a data processing pipeline that sequentially
performs transformations and computations on input data, then outputs the
Copy link
Member

Choose a reason for hiding this comment

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

"input data" sounds like data that you send with the command. It think this working could be better: "data from the MongoDB database"

@ccho-mongodb
Copy link
Contributor Author

Thanks for fixing the unit tests!

@ccho-mongodb ccho-mongodb merged commit 8bc235c into mongodb:4.3 Apr 18, 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