Skip to content

GODRIVER-3892 Move count to the mongo package.#2483

Open
matthewdale wants to merge 1 commit into
mongodb:masterfrom
matthewdale:godriver3892-move-count
Open

GODRIVER-3892 Move count to the mongo package.#2483
matthewdale wants to merge 1 commit into
mongodb:masterfrom
matthewdale:godriver3892-move-count

Conversation

@matthewdale

@matthewdale matthewdale commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

GODRIVER-3892

Summary

Move the count operation logic from the x/mongo/driver/operation package to the mongo package, 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/operation package.

@mongodb-drivers-pr-bot

Copy link
Copy Markdown
Contributor

API Change Report

./v2/x/mongo/driver/operation

incompatible changes

Count: removed
CountResult: removed
NewCount: removed

@mongodb-drivers-pr-bot

mongodb-drivers-pr-bot Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

🧪 Performance Results

Commit SHA: 969385a

The following benchmark tests for version 6a55a8a3108f4300076bcb05 had statistically significant changes (i.e., |z-score| > 1.96):

Benchmark Measurement % Change Patch Value Stable Region H-Score Z-Score
BenchmarkSingleFindOneByID total_mem_allocs -9.3977 1547319.0000 Avg: 1707814.1893
Med: 1716398.0000
Stdev: 72627.2606
0.7460 -2.2098
BenchmarkSingleFindOneByID total_bytes_allocated -9.2228 96521784.0000 Avg: 106328183.4105
Med: 106922612.0000
Stdev: 4659869.0920
0.7363 -2.1044
BenchmarkBSONDeepDocumentEncoding ns_per_op 8.9062 16171.0000 Avg: 14848.5602
Med: 14916.0000
Stdev: 520.1354
0.7765 2.5425
BenchmarkSingleFindOneByID total_time_seconds -8.8134 1.0469 Avg: 1.1481
Med: 1.1537
Stdev: 0.0469
0.7425 -2.1569
BenchmarkBSONDeepDocumentEncoding ops_per_second_med -8.2706 66379.0242 Avg: 72363.9797
Med: 71782.3559
Stdev: 2699.7372
0.7457 -2.2169
BenchmarkBSONDeepDocumentEncoding ops_per_second_max -7.7407 69915.4024 Avg: 75781.3844
Med: 75250.2069
Stdev: 2554.4146
0.7539 -2.2964
BenchmarkSingleRunCommand total_time_seconds -6.5711 1.0559 Avg: 1.1301
Med: 1.1312
Stdev: 0.0337
0.7574 -2.2014
BenchmarkBSONFullDocumentEncoding total_mem_allocs -3.8588 1488737.0000 Avg: 1548489.7708
Med: 1549221.5000
Stdev: 26265.6459
0.7557 -2.2749
BenchmarkBSONFullDocumentEncoding total_bytes_allocated -3.7948 257720520.0000 Avg: 267886177.6250
Med: 268013752.0000
Stdev: 4510530.2259
0.7534 -2.2538
BenchmarkBSONFlatDocumentEncoding total_time_seconds -3.2346 1.1536 Avg: 1.1922
Med: 1.1926
Stdev: 0.0181
0.7473 -2.1270
BenchmarkBSONDeepDocumentEncoding total_time_seconds 2.0111 1.2176 Avg: 1.1936
Med: 1.1941
Stdev: 0.0093
0.7988 2.5777
BenchmarkLargeDocInsertOne allocated_bytes_per_op -0.2387 5680.0000 Avg: 5693.5909
Med: 5695.0000
Stdev: 5.0937
0.8374 -2.6682
BenchmarkBSONDeepDocumentEncoding allocated_bytes_per_op 0.1691 2147.0000 Avg: 2143.3757
Med: 2143.0000
Stdev: 1.5443
0.7611 2.3470

For a comprehensive view of all microbenchmark results for this PR's commit, please check out the Evergreen perf task for this patch.

@matthewdale matthewdale added review-priority-low Low Priority PR for Review: within 3 business days ignore-for-release labels Jul 11, 2026
@matthewdale matthewdale force-pushed the godriver3892-move-count branch from 6e1c991 to 969385a Compare July 14, 2026 03:10
@matthewdale matthewdale added review-priority-normal Medium Priority PR for Review: within 1 business day and removed review-priority-low Low Priority PR for Review: within 3 business days labels Jul 14, 2026
@matthewdale matthewdale marked this pull request as ready for review July 14, 2026 04:40
@matthewdale matthewdale requested a review from a team as a code owner July 14, 2026 04:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 Count operation implementation from x/mongo/driver/operation.
  • Added an unexported countOp implementation in mongo/ to execute the count command and parse results.
  • Updated Collection.EstimatedDocumentCount to construct and run countOp directly, setting comment/rawData fields 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.

Comment thread mongo/op_count.go
return err
}

// Execute runs this operations and returns an error if the operation did not execute successfully.
Comment thread mongo/op_count.go
Comment on lines +105 to +107
if c.deployment == nil {
return errors.New("the Count operation must have a Deployment set before Execute can be called")
}
Comment thread mongo/op_count.go
Comment on lines +69 to +80
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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ignore-for-release review-priority-normal Medium Priority PR for Review: within 1 business day

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants