Skip to content

GODRIVER-4000 Extend addCommandFields to all Collection & IndexView APIs#2460

Open
FGasper wants to merge 3 commits into
mongodb:masterfrom
FGasper:GODRIVER-4000-index-crud-addcommandfields
Open

GODRIVER-4000 Extend addCommandFields to all Collection & IndexView APIs#2460
FGasper wants to merge 3 commits into
mongodb:masterfrom
FGasper:GODRIVER-4000-index-crud-addcommandfields

Conversation

@FGasper

@FGasper FGasper commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

GODRIVER-4000

Summary

GODRIVER-3668 added an addCommandFields mechanism to several mongo.Collection methods. This extends that pattern so that all Collection and IndexView methods can pass arbitrary top-level parameters in server requests.

The Aggregate and Watch commands are omitted here because these already allow arbitrary top-level parameters via SetCustom.

IMPORTANT: This facility is meant for internal MongoDB use and is not supported in customer applications.

Background & Motivation

See GODRIVER-4000.

@FGasper FGasper marked this pull request as ready for review July 3, 2026 13:47
@FGasper FGasper requested a review from a team as a code owner July 3, 2026 13:47
@FGasper FGasper requested review from Copilot and prestonvasquez July 3, 2026 13:47
@mongodb-drivers-pr-bot

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

Copy link
Copy Markdown
Contributor

🧪 Performance Results

Commit SHA: 6fb45b8

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

Benchmark Measurement % Change Patch Value Stable Region H-Score Z-Score
BenchmarkMultiFindMany ops_per_second_min -86.9147 4697.3718 Avg: 35898.1055
Med: 37123.6589
Stdev: 15000.5981
0.7265 -2.0800
BenchmarkMultiInsertSmallDocument total_time_seconds 30.7148 1.3841 Avg: 1.0589
Med: 1.0433
Stdev: 0.0478
0.9280 6.8050
BenchmarkMultiInsertSmallDocument total_mem_allocs 15.4085 2698011.0000 Avg: 2337791.9101
Med: 2312177.5000
Stdev: 133826.5473
0.8162 2.6917
BenchmarkMultiInsertSmallDocument ns_per_op 13.4967 7182.0000 Avg: 6327.9394
Med: 6316.0000
Stdev: 173.5852
0.8916 4.9201
BenchmarkMultiInsertSmallDocument total_bytes_allocated 10.7888 506688672.0000 Avg: 457346450.5169
Med: 455283692.0000
Stdev: 17111548.3692
0.8254 2.8836
BenchmarkLargeDocInsertOne ops_per_second_max -8.1910 5849.4926 Avg: 6371.3698
Med: 6341.3551
Stdev: 131.8348
0.8569 -3.9586
BenchmarkLargeDocInsertOne total_time_seconds 7.7380 1.2738 Avg: 1.1823
Med: 1.1824
Stdev: 0.0241
0.8574 3.7895
BenchmarkLargeDocInsertOne ns_per_op 6.7609 190007.0000 Avg: 177974.3898
Med: 177205.0000
Stdev: 4727.7009
0.7873 2.5451
BenchmarkLargeDocInsertOne ops_per_second_med -6.1552 5507.6846 Avg: 5868.9313
Med: 5868.2176
Stdev: 145.5206
0.7750 -2.4824

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

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

Extends the existing internal-only addCommandFields mechanism so more mongo.Collection and mongo.IndexView APIs can inject arbitrary top-level fields into the commands sent to the server (primarily for internal MongoDB use).

Changes:

  • Adds "addCommandFields" handling to additional internal option setters in x/mongo/driver/xoptions, including a new setter for DropCollectionOptions.
  • Plumbs “additional command fields” through multiple operation.* command builders (and improves marshal error wrapping in several existing paths).
  • Wires the internal option through corresponding mongo.Collection / mongo.IndexView methods and adds unit + integration coverage for many of the newly-supported APIs.

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
x/mongo/driver/xoptions/options.go Adds "addCommandFields" support to more internal option setters and introduces SetInternalDropCollectionOptions.
x/mongo/driver/xoptions/options_test.go Adds a unit test verifying each supported setter stores a bson.D under Internal["addCommandFields"].
x/mongo/driver/operation/update.go Wraps marshal errors for additional command fields with context.
x/mongo/driver/operation/list_indexes.go Adds additionalCmd plumbing + AdditionalCmd setter and appends fields into the command document.
x/mongo/driver/operation/find.go Adds additionalCmd plumbing + AdditionalCmd setter and appends fields into the command document.
x/mongo/driver/operation/find_and_modify.go Wraps marshal errors for additional command fields with context.
x/mongo/driver/operation/drop_indexes.go Adds additionalCmd plumbing + AdditionalCmd setter and appends fields into the command document.
x/mongo/driver/operation/drop_collection.go Adds additionalCmd plumbing + AdditionalCmd setter and appends fields into the command document.
x/mongo/driver/operation/distinct.go Adds additionalCmd plumbing + AdditionalCmd setter and appends fields into the command document.
x/mongo/driver/operation/delete.go Adds additionalCmd plumbing + AdditionalCmd setter and appends fields into the command document.
x/mongo/driver/operation/create_indexes.go Adds additionalCmd plumbing + AdditionalCmd setter and appends fields into the command document.
x/mongo/driver/operation/count.go Adds additionalCmd plumbing + AdditionalCmd setter and appends fields into the command document.
x/mongo/driver/operation/aggregate.go Adds additionalCmd plumbing + AdditionalCmd setter and appends fields into the command document (in addition to existing customOptions).
mongo/options/dropcollectionoptions.go Adds a deprecated Internal optionsutil.Options field to support internal-only options for Drop.
mongo/insert.go Wraps marshal errors for additional command fields with context.
mongo/index_view.go Reads Internal["addCommandFields"] and forwards to List/Create/Drop index operations.
mongo/collection.go Reads Internal["addCommandFields"] and forwards to several operations; extends Drop path to forward additional fields (including encrypted collection handling).
mongo/client_bulk_write.go Wraps marshal errors for additional command fields with context.
internal/integration/collection_test.go Adds an integration test that validates injected top-level fields appear in started command events for newly-supported collection/index methods.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread x/mongo/driver/operation/aggregate.go Outdated
Comment on lines +54 to +58
@@ -53,6 +55,7 @@ type Aggregate struct {
timeout *time.Duration
omitMaxTimeMS bool
rawData *bool
additionalCmd bson.D
Comment on lines +2412 to +2416
// TestAddCommandFields verifies that the "addCommandFields" internal option
// injects arbitrary top-level fields into the command sent to the server for
// each collection- and index-level method that supports it. Each subtest
// injects a "comment" field (accepted by these commands on 4.4+) and asserts
// that it appears in the started command event.
@mongodb-drivers-pr-bot

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

Copy link
Copy Markdown
Contributor

API Change Report

./v2/mongo/options

incompatible changes

DropCollectionOptions: old is comparable, new is not

compatible changes

DropCollectionOptions.Internal: added

./v2/x/mongo/driver/operation

incompatible changes

DropCollection: old is comparable, new is not
DropIndexes: old is comparable, new is not

compatible changes

(*Count).AdditionalCmd: added
(*CreateIndexes).AdditionalCmd: added
(*Delete).AdditionalCmd: added
(*Distinct).AdditionalCmd: added
(*DropCollection).AdditionalCmd: added
(*DropIndexes).AdditionalCmd: added
(*Find).AdditionalCmd: added
(*ListIndexes).AdditionalCmd: added

./v2/x/mongo/driver/xoptions

compatible changes

SetInternalDropCollectionOptions: added

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

Copilot reviewed 18 out of 18 changed files in this pull request and generated no new comments.

@dariakp dariakp changed the title Extend addCommandFields to all Collection & IndexView APIs GODRIVER-4000 Extend addCommandFields to all Collection & IndexView APIs Jul 6, 2026
@prestonvasquez prestonvasquez removed their request for review July 8, 2026 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants