GODRIVER-3892 Move count to the mongo package.#2483
Conversation
API Change Report./v2/x/mongo/driver/operationincompatible changesCount: removed |
🧪 Performance ResultsCommit SHA: 908dbd0The following benchmark tests for version 6a566e47d624a600077830dd had statistically significant changes (i.e., |z-score| > 1.96):
For a comprehensive view of all microbenchmark results for this PR's commit, please check out the Evergreen perf task for this patch. |
6e1c991 to
969385a
Compare
There was a problem hiding this comment.
Pull request overview
This PR moves the internal “count” operation implementation out of x/mongo/driver/operation and into the mongo package, simplifying EstimatedDocumentCount by removing the chainable setter style and keeping the moved types unexported.
Changes:
- Removed the legacy
Countoperation implementation fromx/mongo/driver/operation. - Added an unexported
countOpimplementation inmongo/to execute the count command and parse results. - Updated
Collection.EstimatedDocumentCountto construct and runcountOpdirectly, settingcomment/rawDatafields without setters.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| x/mongo/driver/operation/count.go | Removes the previous Count operation implementation from the x/ operations layer. |
| mongo/op_count.go | Adds the new unexported countOp + result parsing logic in the mongo package. |
| mongo/collection.go | Switches EstimatedDocumentCount from operation.NewCount() to the new countOp struct literal wiring. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| case "cursor": // for count using aggregate with $collStats | ||
| firstBatch, err := element.Value().Document().LookupErr("firstBatch") | ||
| if err != nil { | ||
| return cr, err | ||
| } | ||
|
|
||
| // get count value from first batch | ||
| val := firstBatch.Array().Index(0) | ||
| count, err := val.Document().LookupErr("n") | ||
| if err != nil { | ||
| return cr, err | ||
| } |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
| cr.N, ok = count.AsInt64OK() | ||
| if !ok { | ||
| return cr, fmt.Errorf("response field 'n' is type int64, but received BSON type %s", | ||
| element.Value().Type) |
There was a problem hiding this comment.
[nit]
| element.Value().Type) | |
| count.Type) |
GODRIVER-3892
Summary
Move the count operation logic from the
x/mongo/driver/operationpackage to themongopackage, removing the unnecessary chainable setters. Don't export the moved types.Background & Motivation
Part of a larger effort to reduce unnecessary code by removing the
x/mongo/driver/operationpackage.