-
Notifications
You must be signed in to change notification settings - Fork 455
Add test_example_59 #1143
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
Add test_example_59 #1143
Conversation
Test skeleton contains comment of Python example code for what this example should perform.
value = bson_iter_value (&iter); | ||
if (value->value_type == BSON_TYPE_INT32) { | ||
*accumulator += value->value.v_int32; | ||
} else if (value->value_type == BSON_TYPE_INT32) { | ||
*accumulator += value->value.v_int64; | ||
} else { | ||
MONGOC_ERROR ("%s", "'adoptableCount' must be an integer"); | ||
rc = false; | ||
goto cleanup; | ||
} |
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.
Suggest using bson_iter_as_int64
to handle multiple possible numeric types.
value = bson_iter_value (&iter); | |
if (value->value_type == BSON_TYPE_INT32) { | |
*accumulator += value->value.v_int32; | |
} else if (value->value_type == BSON_TYPE_INT32) { | |
*accumulator += value->value.v_int64; | |
} else { | |
MONGOC_ERROR ("%s", "'adoptableCount' must be an integer"); | |
rc = false; | |
goto cleanup; | |
} | |
*accumulator += bson_iter_as_int64 (&iter); |
Looking good. Include CDRIVER-4295 in the commit message before merging. That will result in a comment with the commit being added to the Jira ticket. |
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! I left one comment about adding more explanation in one part of the example, but I don't think it should block merging if the added explanation is unnecessary.
|
||
accumulate_adoptable_count (cats_collection, &adoptable_pets_count); | ||
accumulate_adoptable_count (dogs_collection, &adoptable_pets_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.
It might be helpful to add a comment here describing that we are using an aggregation pipeline to return the count, since other drivers have been displaying the aggregation pipeline command used. The comment could also be describing how the aggregation pipeline command is omitted.
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'm glad you brought this up, because that's something I'm curious about. It would be a fair amount of duplicate code and a bit lengthy to inline both calls to accumulate_adoptable_count
in this function, but I'm wondering if I should do one of the following:
- Include the entire function
accumulate_adoptable_count
in the example, i.e., place the start example comment just above the declaration ofaccumulate_adoptable_count
, and end example comment stays where it is withintest_example_59
. - Place the text of
accumulate_adoptable_count
in a comment intest_example_59
. - Explain in a comment what is happening in the function
accumulate_adoptable_count
purely in English, and omit code in the comment. - Inline all the code from
accumulate_adoptable_count
withintest_example_59
.
I'm leaning towards 1., but I'm not sure how that would look when rendered. I'd like to know what everyone thinks about this, since I'm not sure which way would be the cleanest for the purpose of producing an example.
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.
P.S. I'm planning on reaching out to Jeffrey Allen, the reporter for the original ticket, regarding this before merging.
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 it would be the most helpful to include the entire function, but since that is many more lines of code than the Python example, we could do option 3 and just describe the aggregation pipeline run. There are other pages (like this one in the C documentation that walks through writing an aggregation pipeline, so it might not be necessary to show every single step in accumulate_adoptable_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.
Good point. One detail that would be good to include is that the client session must be appended to the options passed to mongoc_collection_aggregate
. If we go with option 3., then I suppose that could be explained also in a comment, but it seems like showing the code for it would be the best.
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 got some feed back from Jeffery Allen. It sounds like he's in favor of option 3.
(quote from Jeff)
Hey Kyle, thanks for reaching out. So my recollection with that ticket is that the main goal is to emphasize the snapshot functionality in the example. Therefore, I'm inclined to say that we can exclude the agg pipeline from the example, and leave a comment explaining the aggregation. That way, users aren't too overwhelmed by a large example and they'll still be able to see the snapshot behavior in action
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 agree option 3 would be the clearest, but I'm also not sure about how strict the formatting constraints are. Maybe the docs team could help make the choice.
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 just saw the addition of the comment! Ignore my comment above.
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.
That's interesting. I do like when an example is explicit, since this example includes 2 functions, then I suppose no reason why I can't either. I'll make that change for now, and request another review from both you and Kevin to see what you think.
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.
Defer to Jeff's judgement since this example is requested by the documentation team.
/* | ||
* Perform the following aggregation pipeline, and accumulate the count in | ||
* `adoptable_pets_count`. | ||
* | ||
* adoptablePetsCount = db.cats.aggregate( | ||
* [ { "$match": { "adoptable": true } }, | ||
* { "$count": "adoptableCatsCount" } ], session=s | ||
* ).next()["adoptableCatsCount"] | ||
* | ||
* adoptablePetsCount += db.dogs.aggregate( | ||
* [ { "$match": { "adoptable": True} }, | ||
* { "$count": "adoptableDogsCount" } ], session=s | ||
* ).next()["adoptableDogsCount"] | ||
* | ||
* Remember in order to apply the client session to | ||
* this operation, you must append the client session to the options passed | ||
* to `mongoc_collection_aggregate, i.e., | ||
* | ||
* mongoc_client_session_append (cs, &opts, &error); | ||
* cursor = mongoc_collection_aggregate ( | ||
* collection, MONGOC_QUERY_NONE, pipeline, &opts, NULL); | ||
*/ | ||
accumulate_adoptable_count (cs, cats_collection, &adoptable_pets_count); | ||
accumulate_adoptable_count (cs, dogs_collection, &adoptable_pets_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.
Jeff has checked off on using this comment as a part of the documentation.
FYI, Gil brought up that another C driver example is lengthy and has multiple functions, so it seems that if I were to include multiple functions as a part of the example, that would fit with how things are currently shown. I pushed that in order for us to compare and decide which way we would prefer. For reference, the example that Gil found: https://www.mongodb.com/docs/v6.0/core/transactions/ |
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 the example looks good! I just have one question about using python in this example.
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 small fixes.
|
||
accumulate_adoptable_count (cats_collection, &adoptable_pets_count); | ||
accumulate_adoptable_count (dogs_collection, &adoptable_pets_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.
Defer to Jeff's judgement since this example is requested by the documentation team.
Co-authored-by: Kevin Albertson <[email protected]>
Co-authored-by: Kevin Albertson <[email protected]>
Co-authored-by: Kevin Albertson <[email protected]>
CDRIVER-4295
related: DRIVERS-2181
Implement a snapshot query example for the manual.