GODRIVER-4000 Extend addCommandFields to all Collection & IndexView APIs#2460
GODRIVER-4000 Extend addCommandFields to all Collection & IndexView APIs#2460FGasper wants to merge 3 commits into
addCommandFields to all Collection & IndexView APIs#2460Conversation
🧪 Performance ResultsCommit SHA: 6fb45b8The following benchmark tests for version 6a47c25895438a0007ed17a5 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. |
There was a problem hiding this comment.
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 inx/mongo/driver/xoptions, including a new setter forDropCollectionOptions. - 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.IndexViewmethods 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.
| @@ -53,6 +55,7 @@ type Aggregate struct { | |||
| timeout *time.Duration | |||
| omitMaxTimeMS bool | |||
| rawData *bool | |||
| additionalCmd bson.D | |||
| // 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. |
API Change Report./v2/mongo/optionsincompatible changesDropCollectionOptions: old is comparable, new is not compatible changesDropCollectionOptions.Internal: added ./v2/x/mongo/driver/operationincompatible changesDropCollection: old is comparable, new is not compatible changes(*Count).AdditionalCmd: added ./v2/x/mongo/driver/xoptionscompatible changesSetInternalDropCollectionOptions: added |
addCommandFields to all Collection & IndexView APIsaddCommandFields to all Collection & IndexView APIs
GODRIVER-4000
Summary
GODRIVER-3668 added an
addCommandFieldsmechanism 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.