Skip to content

Conversation

@jemiahw
Copy link
Collaborator

@jemiahw jemiahw commented Mar 26, 2025

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

The migration guide for 1.x -> 2.x is https://github.com/mongodb/mongo-go-driver/blob/master/docs/migration-2.0.md

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
Copy link

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 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))
Copy link

Copilot AI Mar 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
}

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants