GODRIVER-3892 Move count to the mongo package.#2483
Conversation
API Change Report./v2/x/mongo/driver/operationincompatible changesCount: removed |
🧪 Performance ResultsCommit SHA: 969385aThe following benchmark tests for version 6a55a8a3108f4300076bcb05 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.
| return err | ||
| } | ||
|
|
||
| // Execute runs this operations and returns an error if the operation did not execute successfully. |
| if c.deployment == nil { | ||
| return errors.New("the Count operation must have a Deployment set before Execute can be called") | ||
| } |
| 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 | ||
| } |
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.