-
Notifications
You must be signed in to change notification settings - Fork 919
GODRIVER-2962 Merge insert operation into mongo package. #2264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
GODRIVER-2962 Merge insert operation into mongo package. #2264
Conversation
API Change Report./v2/x/mongo/driver/operationincompatible changesInsert: removed |
🧪 Performance ResultsCommit SHA: 986c539The following benchmark tests for version 69392019679161000769cb63 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.
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 insert operation logic from the x/mongo/driver/operation package to the mongo package as part of an effort to remove the x/mongo/driver/operations package. The refactoring replaces the chainable setter pattern with direct field assignment and changes exported types to unexported ones.
Key changes:
- Removed
x/mongo/driver/operation/insert.goand createdmongo/insert.gowith unexported types - Updated
Collection.insert()andbulkWrite.runInsert()to use struct literals instead of chainable setters - Modified test utilities to use the public
mongoclient API instead of the low-level insert operation
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| x/mongo/driver/operation/insert.go | Deleted file containing the original Insert operation implementation |
| mongo/insert.go | New file with unexported insert operation moved from the operation package |
| mongo/collection.go | Updated to instantiate insert operation using struct literal |
| mongo/bulk_write.go | Updated to instantiate insert operation using struct literal |
| x/mongo/driver/integration/main_test.go | Modified insertDocs helper to use mongo.Client API instead of operation package |
| x/mongo/driver/integration/insert_test.go | Deleted test file that used the operation package directly |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // from dropping the database after we've inserted data. | ||
| integtest.Topology(t) | ||
|
|
||
| client, err := mongo.Connect(options.Client().ApplyURI(connectionString.Original).SetWriteConcern(writeConcern)) |
Copilot
AI
Dec 10, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The mongo.Connect call does not specify a context parameter. While this may work with the current API, it's better practice to pass context.Background() or another appropriate context to ensure proper cancellation and timeout behavior.
| }() | ||
|
|
||
| coll := client.Database(dbname).Collection(colname) | ||
| _, err = coll.InsertMany(context.Background(), docs) |
Copilot
AI
Dec 10, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
InsertMany expects a slice of interface{} but docs is []bsoncore.Document. This type mismatch will cause a compilation error. The documents should be converted to []interface{} or the function signature should be adjusted to accept the correct type.
| _, err = coll.InsertMany(context.Background(), docs) | |
| // Convert []bsoncore.Document to []interface{} for InsertMany | |
| docsInterface := make([]interface{}, len(docs)) | |
| for i, doc := range docs { | |
| docsInterface[i] = doc | |
| } | |
| _, err = coll.InsertMany(context.Background(), docsInterface) |
GODRIVER-2962
Summary
Move the insert operation logic from the
x/mongo/driver/operationspackage 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/operationspackage.