You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Part of the easymongo refactor (see PLAN.md on branch claude/mongotest-easymongo-refactor-wu2vhm). First step of the go.mongodb.org/mongo-driver v1 to go.mongodb.org/mongo-driver/v2 migration. The existing test suite is the regression net and must stay green after each issue.
Working context (read this first)
Repository github.com/tophergopher/easymongo. Start from branch claude/mongotest-easymongo-refactor-wu2vhm; create a branch issue-<number>-<short-slug> from it and open a pull request back into it. PLAN.md on that branch is the source of truth; read it before writing code.
Go project, single module, all packages at the repo root except the new easymongotest/ subpackage. The final toolchain target is Go 1.27 (set by Toolchain: go 1.27, latest dependencies, tidy, remove replace directives #10); any Go 1.24 or newer works until then. Before pushing: gofmt -l . prints nothing, go vet ./..., go test -race ./....
The existing test suite (*_test.go at the root, package easymongo_test, every test function calling setup(t) from common_test.go) is the regression net for this refactor. It must pass after your change. It needs a Docker daemon reachable through the normal Docker environment and the mongo:8 image.
Method is test-driven: write the tests listed under "Tests first", confirm they fail for the expected reason, then implement. Never delete, skip or weaken an existing test to get green; if a test must change because the public API changed (for example primitive.ObjectID to bson.ObjectID), change only the types.
Commit messages: imperative summary line, blank line, body explaining why. Mention this issue number in the pull request description.
Scope (connect.go)
Import paths to go.mongodb.org/mongo-driver/v2/....
mongo.NewClient(opts) + client.Connect(ctx) (currently lines 281/290 and 315/326) become mongo.Connect(opts), which takes no context.
Add Connection.Disconnect(ctx context.Context) error. Nothing in the module calls Disconnect today; easymongotest and tests will.
EnableDebug currently does *conn.client = *client (copies a client struct). Replace with: build new options with the monitor, Disconnect the old client, mongo.Connect a new one, swap the pointer.
Custom registry (bson.NewRegistryBuilder, bsoncodec.NewSliceCodec, bsonoptions.SliceCodec().SetEncodeNilAsEmpty(true), lines 91-107) becomes opts.SetBSONOptions(&options.BSONOptions{NilSliceAsEmpty: true}), still gated on nilSlicesAreNull.
writeconcern.New(writeconcern.W(n)) (line 116) becomes &writeconcern.WriteConcern{W: n}. The []writeconcern.Option accumulation in mongoDriverDatabaseOptions and mongoDriverClientOptions (lines 471-484, 520-535) becomes direct struct construction: W as int or "majority", Journal: &true for WriteConcernJournal.
readconcern.*() and readpref.*() constructors are unchanged in v2; keep them.
event.CommandFailedEvent.Failure is an error in v2; adjust the debug monitor formatting.
options.Database() builder and options.ListDatabases() still exist; verify SetReadConcern/SetReadPreference/SetWriteConcern signatures.
Note the old client-options code applied W1, W2 and W3 cumulatively (later ifs overwrote earlier ones); pick the highest as above and mention it in the pull request.
Write Disconnect so that a second call is a no-op returning nil (the driver returns mongo.ErrClientDisconnected on double disconnect; swallow exactly that error).
Tests first (connect_test.go)
Disconnect succeeds and a subsequent Ping returns an error.
EnableDebug keeps the connection usable (ping succeeds afterwards) and the debug logger receives at least one Debugf call for a command.
Nil slice encoding: insert a struct with a nil []string, read back raw BSON, assert it is an empty array by default and null when nilSlicesAreNull is set.
Write concern flags produce the expected WriteConcern values (unit test on mongoDriverClientOptions without a server).
Acceptance
go build ./... succeeds with only connect.go and connect_test.go on driver v2 (other files may temporarily import v1 through a replace-free dual requirement; remove the v1 requirement in the final migration issue).
Depends on: #8 (test suite on easymongotest). Lands in one pull request together with #3, #4 and #5, worked in that order.
Part of the easymongo refactor (see
PLAN.mdon branchclaude/mongotest-easymongo-refactor-wu2vhm). First step of thego.mongodb.org/mongo-driverv1 togo.mongodb.org/mongo-driver/v2migration. The existing test suite is the regression net and must stay green after each issue.Working context (read this first)
github.com/tophergopher/easymongo. Start from branchclaude/mongotest-easymongo-refactor-wu2vhm; create a branchissue-<number>-<short-slug>from it and open a pull request back into it.PLAN.mdon that branch is the source of truth; read it before writing code.easymongotest/subpackage. The final toolchain target is Go 1.27 (set by Toolchain: go 1.27, latest dependencies, tidy, remove replace directives #10); any Go 1.24 or newer works until then. Before pushing:gofmt -l .prints nothing,go vet ./...,go test -race ./....*_test.goat the root, packageeasymongo_test, every test function callingsetup(t)fromcommon_test.go) is the regression net for this refactor. It must pass after your change. It needs a Docker daemon reachable through the normal Docker environment and themongo:8image.*mongo.Clienttype flows fromConnectiontoDatabasetoCollection), so the four driver issues Driver v2: migrate connect.go (mongo.Connect, Disconnect, BSONOptions, write concern) #2, Driver v2: options struct literals become builders; drop MaxTime; ArrayFilters and Delete option changes #3, Driver v2: primitive package merged into bson; replace x/bsonx in index.go #4 and Driver v2: Distinct returns a DistinctResult that must be decoded #5 land together in one pull request, worked in that order. Before them, New easymongotest subpackage wrapping mongotest/v2 #7 and Switch the easymongo test suite to easymongotest #8 must land so the test suite no longer depends on the oldgithub.com/tophergopher/mongotestv0.1.0 module (which itself imports easymongo and breaks the moment easymongo's types change). Until mongotest'sv2module is tagged, use a localreplace github.com/tophergopher/mongotest/v2 => ../mongotest/v2ingo.modand say so in the pull request; Toolchain: go 1.27, latest dependencies, tidy, remove replace directives #10 removes it.primitive.ObjectIDtobson.ObjectID), change only the types.Scope (
connect.go)go.mongodb.org/mongo-driver/v2/....mongo.NewClient(opts)+client.Connect(ctx)(currently lines 281/290 and 315/326) becomemongo.Connect(opts), which takes no context.Connection.Disconnect(ctx context.Context) error. Nothing in the module callsDisconnecttoday;easymongotestand tests will.EnableDebugcurrently does*conn.client = *client(copies a client struct). Replace with: build new options with the monitor,Disconnectthe old client,mongo.Connecta new one, swap the pointer.bson.NewRegistryBuilder,bsoncodec.NewSliceCodec,bsonoptions.SliceCodec().SetEncodeNilAsEmpty(true), lines 91-107) becomesopts.SetBSONOptions(&options.BSONOptions{NilSliceAsEmpty: true}), still gated onnilSlicesAreNull.writeconcern.New(writeconcern.W(n))(line 116) becomes&writeconcern.WriteConcern{W: n}. The[]writeconcern.Optionaccumulation inmongoDriverDatabaseOptionsandmongoDriverClientOptions(lines 471-484, 520-535) becomes direct struct construction:Wasintor"majority",Journal: &trueforWriteConcernJournal.readconcern.*()andreadpref.*()constructors are unchanged in v2; keep them.event.CommandFailedEvent.Failureis anerrorin v2; adjust the debug monitor formatting.options.Database()builder andoptions.ListDatabases()still exist; verifySetReadConcern/SetReadPreference/SetWriteConcernsignatures.Implementation details
Verified v2.9.0 signatures you will use:
Replacement for the write concern flag mapping (
mongoDriverClientOptionsandmongoDriverDatabaseOptions):Note the old client-options code applied W1, W2 and W3 cumulatively (later
ifs overwrote earlier ones); pick the highest as above and mention it in the pull request.EnableDebugrewrite:Write
Disconnectso that a second call is a no-op returning nil (the driver returnsmongo.ErrClientDisconnectedon double disconnect; swallow exactly that error).Tests first (
connect_test.go)Disconnectsucceeds and a subsequentPingreturns an error.EnableDebugkeeps the connection usable (ping succeeds afterwards) and the debug logger receives at least oneDebugfcall for a command.[]string, read back raw BSON, assert it is an empty array by default andnullwhennilSlicesAreNullis set.WriteConcernvalues (unit test onmongoDriverClientOptionswithout a server).Acceptance
go build ./...succeeds with onlyconnect.goandconnect_test.goon driver v2 (other files may temporarily import v1 through areplace-free dual requirement; remove the v1 requirement in the final migration issue).Depends on: #8 (test suite on easymongotest). Lands in one pull request together with #3, #4 and #5, worked in that order.