Open
Conversation
- Update all import paths from go.mongodb.org/mongo-driver to go.mongodb.org/mongo-driver/v2 - Replace primitive.ObjectID with bson.ObjectID (bson/primitive merged into bson) - Replace mongo.NewClient + client.Connect with mongo.Connect (NewClient removed in v2) - Update transaction API: mongo.Session is now *mongo.Session (concrete type), mongo.SessionContext replaced with context.Context - Update options API: use options.Lister[T] generic interface for collection method parameters (FindOneOptions, InsertOneOptions, UpdateOneOptions, etc.) - Replace UpsertTrueOption to use options.UpdateOne().SetUpsert(true) builder - Bump minimum Go version from 1.17 to 1.22 - Update Travis CI to test against Go 1.22.x and 1.23.x https://claude.ai/code/session_01SBGcfD2L5xdCZxmVVxMMcQ
- field_test.go: Tests for DateFields.Creating/Saving hooks (timestamp setting), IDField.GetID/SetID (including panic on wrong type), PrepareID edge cases (empty string, short hex, nil, non-string passthrough) - hooks_internal_test.go: Tests for hook fallback logic (WithCtx preferred over legacy), context propagation, error short-circuiting, no-hook models - util_test.go: Strengthen UpsertTrueOption test to verify List() output https://claude.ai/code/session_01SBGcfD2L5xdCZxmVVxMMcQ
Integration tests (collection_test.go): - FindByID with ObjectID, hex string, empty string - FindByID/Create/Update/SimpleFind with options.Lister passthrough - Context cancellation for FindByID, Create, SimpleFind - Create/Update timestamp verification - Update with UpsertTrueOption - SimpleFind on empty collection, with limit/sort options - SimpleAggregate with empty stages, mixed builder/bson.M stages - SimpleAggregateCursor with context Integration tests (transaction_test.go): - Transaction error propagation - Multi-operation commit - TransactionWithClient explicit client Connection tests (connection_test.go): - Context deadline matches configured timeout - NewCtx with custom timeout - SetDefaultConfig with custom timeout - CollectionByName with various names Escape tests (escape_test.go): - Empty string, single-char ($, .), multiples, unicode passthrough - Full round-trip property test Builder edge tests (builder/builder_edge_test.go): - All-nil params for every aggregate stage builder - Zero/false values (verifying they are NOT filtered as nil) - S() with no operators, multiple operators - Partial nil params for Lookup, Merge, Unwind - Group with nil params map and nil values in params Internal util tests (internal/util/util_test.go): - IsNil: nil, non-nil, nil pointer/slice/map/func/chan, zero values - AnyNil: all-nil, none-nil, mixed, empty args - ToSnakeCase: simple, single word, acronyms, empty, all caps - PanicErr: nil vs error Util tests (util_test.go): - CollectionGetter interface (Coll uses custom collection) - CollName ignores CollectionGetter (uses reflection) - CollName pluralizations (Category, Person, Status) https://claude.ai/code/session_01SBGcfD2L5xdCZxmVVxMMcQ
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.
Summary
This PR upgrades the codebase from MongoDB Go Driver v1 to v2, including comprehensive test coverage for hook execution and field operations.
Key Changes
Driver Upgrade
go.mongodb.org/mongo-drivertogo.mongodb.org/mongo-driver/v2go.modto requirego.mongodb.org/mongo-driver/v2 v2.1.0API Changes for v2 Compatibility
mongo.NewClient()tomongo.Connect()inconnection.go- v2 combines client creation and connection...*options.XxxOptionsto...options.Lister[options.XxxOptions]across:FindByID,First,Create,Update,Delete,ReplaceoperationsNewCollectionandCollectionByNamefunctionsCollutility functionTransactionFuncsignature frommongo.Session, mongo.SessionContextto*mongo.Session, context.Contextprimitive.ObjectIDtobson.ObjectIDthroughout the codebaseNew Test Coverage
hooks_internal_test.gowith comprehensive tests for hook execution:field_test.gowith tests for field operations:DateFieldshook tests forCreatedAtandUpdatedAttimestampsIDFieldtests for ID getters, setters, and ID preparationCode Quality Improvements
requireinstead ofassertwhere appropriateNotable Implementation Details
PrepareIDmethod handles multiple ID formats:bson.ObjectID, hex strings, and pass-through for other typeshttps://claude.ai/code/session_01SBGcfD2L5xdCZxmVVxMMcQ