Skip to content

DOCSP-35982: Count usage example #2850

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 16, 2024
Merged

DOCSP-35982: Count usage example #2850

merged 6 commits into from
Apr 16, 2024

Conversation

norareidy
Copy link
Contributor

@norareidy norareidy commented Apr 12, 2024

JIRA - https://jira.mongodb.org/browse/DOCSP-35982
Staging - https://preview-mongodbnorareidy.gatsbyjs.io/laravel/DOCSP-35982/usage-examples/count/

Checklist

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

Comment on lines 33 to 34
$biographies = Movie::where('genres', 'Biography')
->count();
Copy link
Member

Choose a reason for hiding this comment

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

The 2nd example for "a collection of object" would be:

$biographies = Movie::where('genres', 'Biography')->get();
$count = $biographies->count();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does the where() method return a collection of objects? If so, it seems (from my understanding) accurate to say that I'm calling count() on a "collection of objects" if I chain count() right after where(). If not, I'll change the other code examples that mention a "collection of objects" as well to use get().

Copy link
Member

Choose a reason for hiding this comment

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

where() returns a query builder. Calling ->get() runs the find query and returns the collection of model instances.

Copy link
Contributor

@mongoKart mongoKart left a comment

Choose a reason for hiding this comment

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

LGTM + 1 fix

Comment on lines 38 to 39
- ``where()``: matches documents in which the value of the ``genres`` field includes ``"Biography"``.
- ``count()``: counts the number of matching documents. This method returns an integer value.
Copy link
Contributor

Choose a reason for hiding this comment

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

Style Guide

Suggested change
- ``where()``: matches documents in which the value of the ``genres`` field includes ``"Biography"``.
- ``count()``: counts the number of matching documents. This method returns an integer value.
- ``where()``: Matches documents in which the value of the ``genres`` field includes ``"Biography"``.
- ``count()``: Counts the number of matching documents. This method returns an integer value.

@ccho-mongodb ccho-mongodb marked this pull request as ready for review April 16, 2024 02:14
@ccho-mongodb ccho-mongodb requested a review from a team as a code owner April 16, 2024 02:14
@ccho-mongodb ccho-mongodb merged commit 00d3931 into mongodb:4.1 Apr 16, 2024
This was referenced Apr 16, 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.

4 participants