-
-
Notifications
You must be signed in to change notification settings - Fork 199
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
Possible documentation refinement for the MongoDBContainer module #697
Comments
I bumped into the same issues. FWIW, I've created a minimal example repository that shows the issue when not using Environment Information
|
I'm no Mongo expert.. should |
Also not an expert, but I tested connecting to a natively running MongoDB (using Homebrew) and a containerized MongoDB (launched with |
I've noticed the Java implementation of Testcontainers does not expose this |
@cristianrgreco Hi, by default the code creates a Mongodb Replica Set class MongoDBContainer extends testcontainers_1.GenericContainer {
constructor(image = "mongo:4.0.1") {
super(image);
this.withExposedPorts(MONGODB_PORT)
.withCommand(["--replSet", "rs0"])
.withWaitStrategy(testcontainers_1.Wait.forLogMessage(/.*waiting for connections.*/i))
.withStartupTimeout(120000);
}
.... Hence you need to tell the driver to use a direct connection. $ mongosh localhost:55076/somedb
Current Mongosh Log ID: 65d36046a01ccf3f8e133100
Connecting to: mongodb://localhost:55076/somedb?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.1.4 |
This tripped me up as well, as I wasn't expecting Testcontainers to create a replica set by default. I agree that at minimum the docs need to be updated to make this clear and ideally the implementation would support both use cases. |
Thanks all for the feedback. If the docs made it clear that by default the container starts a replica set, and update the connection URI to work appropriately, would you still feel the need to support both use cases? Any PR to address either of these would be very welcome. |
Expected Behaviour
I was following the instructions on the MongoDB Module page and trying to implement in an ES6 environment that outputs CommonJS. The examples don't include the
require()/import
statement which would have helped a ton.I also expected that once getting the container running and returning the value from
container.getConnectionString()
that it would simply connect using that string. I found that I had to add?directConnection=true
to the connection string for it to actually connect.Also, the
checkMongo
function seems to be from the test suite instead of from the library itself.Proposed changes:
container.getConnectionString()
to get the connection string back to my testing suite.?directConnection=true
in conjunction with the connection string returned. I ended up concatenating it to the end elsewhere:mongodb://localhost:[PORT]/test-db?directConnection=true
Environment Information
MacOS 14.2 (Apple M1 Max)
24.0.7, build afdd53b
v18.12.1
^10.4.0
The text was updated successfully, but these errors were encountered: