Skip to content

Conversation

@matthewdale
Copy link
Collaborator

@matthewdale matthewdale commented Dec 10, 2025

GODRIVER-2962

Summary

Move the insert operation logic from the x/mongo/driver/operations 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/operations package.

@mongodb-drivers-pr-bot
Copy link
Contributor

API Change Report

./v2/x/mongo/driver/operation

incompatible changes

Insert: removed
InsertResult: removed
NewInsert: removed

@mongodb-drivers-pr-bot
Copy link
Contributor

🧪 Performance Results

Commit SHA: 986c539

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

Benchmark Measurement % Change Patch Value Stable Region H-Score Z-Score
BenchmarkMultiInsertSmallDocument allocated_bytes_per_op -4.9871 2631.0000 Avg: 2769.0979
Med: 2789.0000
Stdev: 67.6814
0.7518 -2.0404
BenchmarkLargeDocInsertOne total_time_seconds 4.6121 1.2367 Avg: 1.1822
Med: 1.1822
Stdev: 0.0232
0.7650 2.3475

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 Dec 10, 2025
@matthewdale matthewdale marked this pull request as ready for review December 10, 2025 21:34
@matthewdale matthewdale requested a review from a team as a code owner December 10, 2025 21:34
Copy link
Contributor

Copilot AI left a 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.go and created mongo/insert.go with unexported types
  • Updated Collection.insert() and bulkWrite.runInsert() to use struct literals instead of chainable setters
  • Modified test utilities to use the public mongo client 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))
Copy link

Copilot AI Dec 10, 2025

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.

Copilot uses AI. Check for mistakes.
}()

coll := client.Database(dbname).Collection(colname)
_, err = coll.InsertMany(context.Background(), docs)
Copy link

Copilot AI Dec 10, 2025

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.

Suggested change
_, 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)

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ignore-for-release review-priority-low Low Priority PR for Review: within 3 business days

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant