-
Notifications
You must be signed in to change notification settings - Fork 26
Docsp-28793: count fundamentals #103
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-28793: count fundamentals #103
Conversation
| You can also include the :manual:`$count </reference/operator/aggregation/count/>` | ||
| stage to count the number of documents in an aggregation pipeline. |
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: Instead of linking to the $count documentation, mention that this method uses the Count() builder method. In the additional information section, you could link to the Server documentation
| - Counts the number of documents where the ``finalGrade`` is greater than ``80`` | ||
| - Assigns the count to the ``count`` 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.
I: this isn't exactly what's happening in this code -- it seems like you are specifying a filter in the match stage and then appending a count stage.
| var matchStage = Builders<Student> | ||
| .Filter.Gt(f => f.finalGrade, 80); | ||
| var pipeline = new EmptyPipelineDefinition<Student>() | ||
| .Match(matchStage).Count(); | ||
| Console.WriteLine(pipeline); |
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: format so that newlined method calls are indented. Also, this code should print the result of the aggregation. LMK if you want to review this code together.
| @@ -0,0 +1,7 @@ | |||
| //start-grades-struct | |||
| public class Student { | |||
| public ObjectId Id { get; 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.
I: Since in your sample data, the id field is ints, make sure that corresponds to the type here
| public ObjectId Id { get; set; } | |
| public int Id { get; set; } |
rustagir
left a comment
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 more things
| { "_id": 6, "name": "Demarcus Smith", "finalGrade": 88.8 } | ||
|
|
||
| The following ``Student`` class models the documents in this | ||
| 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.
| collection. | |
| collection: |
| var filter = Builders<Student>.Filter.Lt(s => s.FinalGrade, 80.0); | ||
| var count = _myColl.CountDocuments(filter); | ||
| Console.WriteLine("Number of documents with a final grade less than 80: " + count); |
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: fix indentation formatting
|
|
||
| var filter = Builders<Student>.Filter.Empty; | ||
| CountOptions opts = new CountOptions(){Hint = "_id_"}; | ||
| var counter = collection.CountDocuments(filter, opts); |
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.
| var counter = collection.CountDocuments(filter, opts); | |
| var count = collection.CountDocuments(filter, opts); |
|
|
||
| .. note:: | ||
|
|
||
| The ``EstimatedDocumentCount()`` method is quicker than 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 ``EstimatedDocumentCount()`` method is quicker than the | |
| The ``EstimatedDocumentCount()`` method is more efficient than the |
| .. io-code-block:: | ||
| :copyable: true | ||
|
|
||
| .. input:: | ||
| :language: csharp | ||
| :dedent: | ||
|
|
||
| var count = _myColl.EstimatedDocumentCount(); | ||
| Console.WriteLine("Estimated number of documents in the students collection: " + count); | ||
|
|
||
| .. output:: | ||
| :language: none | ||
| :visible: false | ||
|
|
||
| Estimated number of documents in the students collection: 6 |
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: example is not showing up in staging because of indentation errors
S: fix errors (text should be aligned with directive)
| Aggregation | ||
| ----------- | ||
|
|
||
| You can also include the ``Count()`` builder method to count the number |
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.
| You can also include the ``Count()`` builder method to count the number | |
| You can use the ``Count()`` builder method to count the number |
| - Specifies a filter in the match stage | ||
| - Appends a count stage using ``Count()`` |
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: describe what is happening in each stage
| - Specifies a filter in the match stage | |
| - Appends a count stage using ``Count()`` | |
| - Specifies a match stage to find documents with a ``FinalGrade`` value greater than ``80`` | |
| - Counts the number of documents that match the criteria |
| var matchStage = Builders<Student> | ||
| .Filter.Gt(s => s.FinalGrade, 80); | ||
| var result = _myColl.Aggregate().Match(matchStage).Count(); | ||
| Console.WriteLine("Number of documents with a final grade more than 80: " + result.First().Count); |
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: indentation error, also, these variables should be renamed correctly
| var matchStage = Builders<Student> | |
| .Filter.Gt(s => s.FinalGrade, 80); | |
| var result = _myColl.Aggregate().Match(matchStage).Count(); | |
| Console.WriteLine("Number of documents with a final grade more than 80: " + result.First().Count); | |
| var filter = Builders<Student> | |
| .Filter.Gt(s => s.FinalGrade, 80); | |
| var result = _myColl.Aggregate().Match(filter).Count(); | |
| Console.WriteLine("Number of documents with a final grade more than 80: " + result.First().Count); |
| new() { Id= 1, Name = "Jonathon Howard ", FinalGrade = 87.5 }, | ||
| new() { Id= 2, Name = "ABCDEF Howard ", FinalGrade = 10.5 }, | ||
| new() { Id= 3, Name = "aeufh Howard ", FinalGrade = 90.5 } |
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: since this is a public repo, make sure that the sample code matches what's in the page.
S: replace with the same sample data as in the page.
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.
Bumping this comment since I dont think you saw it!
rustagir
left a comment
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 but consider changing the two outstanding comments! great work here
| - :ref:`csharp-bson` | ||
| - :ref:`csharp-guids` | ||
| - :ref:`csharp-builders` | ||
| - :ref:`csharp-poco` |
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: add a link to the $count documentation in the Server manual
| new() { Id= 1, Name = "Jonathon Howard ", FinalGrade = 87.5 }, | ||
| new() { Id= 2, Name = "ABCDEF Howard ", FinalGrade = 10.5 }, | ||
| new() { Id= 3, Name = "aeufh Howard ", FinalGrade = 90.5 } |
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.
Bumping this comment since I dont think you saw it!
* DOCSP-28793: Count Fundementals * test * test * test * test * test * up through estimated * up through estimated * aggregate * final? * final? * final? * final * api fix * final except error * final * post review * check before and after * post review * error fix * error fix * error fix * error fix * error fix * error fix * examples too long fix * changes requested * changes requested (cherry picked from commit 173895b)
* DOCSP-28793: Count Fundementals * test * test * test * test * test * up through estimated * up through estimated * aggregate * final? * final? * final? * final * api fix * final except error * final * post review * check before and after * post review * error fix * error fix * error fix * error fix * error fix * error fix * examples too long fix * changes requested * changes requested (cherry picked from commit 173895b)
* DOCSP-28793: Count Fundementals * test * test * test * test * test * up through estimated * up through estimated * aggregate * final? * final? * final? * final * api fix * final except error * final * post review * check before and after * post review * error fix * error fix * error fix * error fix * error fix * error fix * examples too long fix * changes requested * changes requested
Pull Request Info
PR Reviewing Guidelines
JIRA - https://jira.mongodb.org/browse/DOCSP-28793
Staging - https://docs-mongodbcom-staging.corp.mongodb.com/csharp/docsworker-xlarge/DOCSP-28793-count-fundamentals/fundamentals/crud/read-operations/count/
Self-Review Checklist