-
-
Notifications
You must be signed in to change notification settings - Fork 512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: MongoDB WithReplicaSet fails to find server #2672
Comments
This should be fixed by #2699 |
Ey @Chris-Sheridan can you check with latest release from yesterday, If fixed, let's close this one. Thanks! |
I really appreciate everyone's help here. Unfortunately @mdelapenya, it's still not working. I've tried several connection strings, but constantly get an error message 'unable to connect' when trying to ping the cluster. Do you have an example of a connection string that would work? I assume the replicaSet needs to be a part of it. I can dig in more later when I have some time. Also, if I apply WithUsername or WithPassword along with WithReplica, there's an error trying to spin up the container saying the mapped port wasn't created within 5 seconds. |
Mmm here you can find an example for the credentials: https://pkg.go.dev/github.com/testcontainers/testcontainers-go/modules/mongodb#example-Run-WithCredentials, and some tests using the replica set option: https://github.com/testcontainers/testcontainers-go/blob/main/modules/mongodb/mongodb_test.go#L59 We probably need a testable example for the replicaset though. |
try to add "/?replicaSet=&directConnection=true" to connection string |
Thanks @dimboknv! I knew there was a trick to that connection string. It works now, but I found another bug. When you use WithUsername and WithPassword along with the WithReplicaSet options, you get an error. I will open a separate ticket for that and dig in. |
Hey @Chris-Sheridan given you were able to build the right connection string, and you opened a new ticket for your new findings, I'm closing this one. Please reopen if you consider it's not done 🙏 |
I don't know whether this is another bug or I'm using the wrong way. I run WithReplicaSet option only and got failure when connecting use connection string.
However, thank to @dimboknv it worked when I add options to the connection string. Shouldn't ConnectionString method return include |
Testcontainers version
0.32.0
Using the latest Testcontainers version?
Yes
Host OS
MacOS
Host arch
ARM
Go version
1.22.2
Docker version
Client: Cloud integration: v1.0.35+desktop.13 Version: 26.0.0 API version: 1.45 Go version: go1.21.8 Git commit: 2ae903e Built: Wed Mar 20 15:14:46 2024 OS/Arch: darwin/arm64 Context: desktop-linux Server: Docker Desktop 4.29.0 (145265) Engine: Version: 26.0.0 API version: 1.45 (minimum version 1.24) Go version: go1.21.8 Git commit: 8b79278 Built: Wed Mar 20 15:18:02 2024 OS/Arch: linux/arm64 Experimental: false containerd: Version: 1.6.28 GitCommit: ae07eda36dd25f8a1b98dfbf587313b99c0190bb runc: Version: 1.1.12 GitCommit: v1.1.12-0-g51d5e94 docker-init: Version: 0.19.0 GitCommit: de40ad0
Docker info
What happened?
MongoDB testcontainer works brilliantly, but I have multi-collection ACID transactions in my code. When I use the WithReplicaSet, the Go mongo client is unable to find the servers (via ping, calls to collections). The test container provides a connection string (e.g. mongodb://localhost:50144), but it's unreachable from the Go mongodb driver.
I assume this is something related to the Docker network internals, but I am stuck at the moment and appreciate anyone's input.
Test container setup:
mongo, err := mongodb.Run(ctx, "mongo:latest", mongodb.WithReplicaSet("rs0"), )
Client call:
` if client, err = mongo.Connect(ctx, opts); err != nil {
return repo, errors.Join(err, errors.New("unable to connect to MongoDB: "+url))
}
Relevant log output
No response
Additional information
No response
The text was updated successfully, but these errors were encountered: