Open
Conversation
Since this was a major version upgrade there are numerous backward incompatible API changes. Fortunately our usage is pretty basic and few of these affected us. The main changes were: * Replacing primitive.ObjectID related methods with bson.ObjectID equivalent (primitive was merged into the bson package) * Connect no longer requires two-step NewClient+Connect. You just call Connect directly. * A change to how Distinct returned values
There was a problem hiding this comment.
Pull Request Overview
This PR upgrades the MongoDB driver from v1 to v2 and adjusts related code to handle backward‐incompatible changes. Key changes include updating import paths to use the v2 driver, replacing primitive.ObjectID methods with bson equivalents, and simplifying client connection logic.
Reviewed Changes
Copilot reviewed 17 out of 18 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| entity/store.go | Updated imports and ObjectID conversions; changed NewStore signature. |
| entity/store_test.go | Replaced primitive with bson for ObjectID conversions in tests. |
| test/db.go | Refactored client connection to directly call mongo.Connect. |
| cdc/store.go & others | Updated imports and context handling for new driver conventions. |
| api/api_gomux.go, etc. | Updated ObjectID usage in API handling for consistency with driver v2. |
Files not reviewed (1)
- go.mod: Language not supported
Comments suppressed due to low confidence (1)
test/db.go:21
- Consider using a context with a timeout when calling mongo.Connect to prevent indefinite hangs during connection attempts in tests.
client, err := mongo.Connect(options.Client().ApplyURI(url))
| switch p.Value.(type) { | ||
| case string: | ||
| id, _ := primitive.ObjectIDFromHex(p.Value.(string)) | ||
| id, _ := bson.ObjectIDFromHex(p.Value.(string)) |
There was a problem hiding this comment.
Check and handle the error returned by bson.ObjectIDFromHex rather than discarding it to avoid potential panics when an invalid ObjectID string is passed.
Suggested change
| id, _ := bson.ObjectIDFromHex(p.Value.(string)) | |
| id, err := bson.ObjectIDFromHex(p.Value.(string)) | |
| if err != nil { | |
| fmt.Printf("Invalid ObjectID string: %v\n", p.Value.(string)) | |
| continue | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since this was a major version upgrade there are numerous backward incompatible API changes. Fortunately our usage is pretty basic and few of these affected us.
The main changes were:
The migration guide for 1.x -> 2.x is https://github.com/mongodb/mongo-go-driver/blob/master/docs/migration-2.0.md