Skip to content

feat(container): Add Mongo DB container#251

Merged
jarlah merged 4 commits intotestcontainers:mainfrom
PedroI920224:feature/add_mongodb_container
Apr 17, 2026
Merged

feat(container): Add Mongo DB container#251
jarlah merged 4 commits intotestcontainers:mainfrom
PedroI920224:feature/add_mongodb_container

Conversation

@PedroI920224
Copy link
Copy Markdown
Contributor

@PedroI920224 PedroI920224 commented Apr 16, 2026

Eyyy Guys I hope you're doing great here is a PR for MongoDB implementation inspired from Ruby TestContainers.

PR Title

Add new MongoContainer implementation from scratch with Ruby-parity behavior and comprehensive tests

Summary

This PR introduces a brand new MongoContainer implementation for testcontainers-elixir, modeled after testcontainers-ruby Mongo behavior and adapted to Elixir conventions.
It also adds comprehensive test coverage, including a real reachability test against a running Mongo container.

What was added

1) New Mongo container module

Created lib/container/mongo_container.ex (testcontainers-elixir/lib/container/mongo_container.ex) from scratch with:

  • Defaults:
    • image: mongo:latest
    • username/password/database: test
    • port: 27017
    • wait timeout: 180_000
  • Builder APIs:
    • new/0
    • with_image/2
    • with_user/2
    • with_username/2 (alias for Ruby-style naming)
    • with_password/2
    • with_database/2
    • with_port/2
    • with_persistent_volume/2
    • with_wait_timeout/2
    • with_check_image/2
    • with_reuse/2
  • Runtime helpers:
    • port/1
    • connection_parameters/1
    • mongo_url/2
    • database_url/2 (alias)
  • ContainerBuilder implementation:
    • sets proper Mongo init env vars:
      • MONGO_INITDB_ROOT_USERNAME
      • MONGO_INITDB_ROOT_PASSWORD
      • MONGO_INITDB_DATABASE
    • configures volume mount at /data/db
    • uses command wait strategy with Mongo readiness ping:
      • mongosh ... db.adminCommand('ping') with mongo fallback

@jarlah
Copy link
Copy Markdown
Member

jarlah commented Apr 16, 2026

Irrelevant /Users/Ivan path. Pr description auto generated ?

Copy link
Copy Markdown
Member

@jarlah jarlah left a comment

Choose a reason for hiding this comment

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

A couple of comments from me looking at the code. I think the most "important" was a missing function comment/doc.

Comment thread lib/container/mongo_container.ex Outdated
Comment thread lib/container/mongo_container.ex
Comment thread lib/container/mongo_container.ex
Comment thread test/container/mongo_container_test.exs
Comment thread lib/container/mongo_container.ex
Copy link
Copy Markdown
Member

@jarlah jarlah left a comment

Choose a reason for hiding this comment

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

Exact failure on all versions. Maybe run tests locally and fix the test failures?

@PedroI920224
Copy link
Copy Markdown
Contributor Author

@jarlah sorry to bother you, but for DBs containers is needed to update lib/mix/tasks/testcontainers/run.ex ?

There we have some implementation via mix task.

@jarlah
Copy link
Copy Markdown
Member

jarlah commented Apr 16, 2026

@jarlah sorry to bother you, but for DBs containers is needed to update lib/mix/tasks/testcontainers/run.ex ?

There we have some implementation via mix task.

No. Thats just for phoenix apps. No need

@PedroI920224
Copy link
Copy Markdown
Contributor Author

@jarlah I hope you are doing great, I already solved most of the comments, I'll apreciate if you can re take a look and let me know if missing something else.

Comment thread mix.exs Outdated
@jarlah
Copy link
Copy Markdown
Member

jarlah commented Apr 17, 2026

great work :) i just need you to bump to latest version of the mongo dep

@PedroI920224
Copy link
Copy Markdown
Contributor Author

Thanks by the feedback :) @jarlah

Copy link
Copy Markdown
Member

@jarlah jarlah left a comment

Choose a reason for hiding this comment

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

Simple, focused, works. I will fix the flaky test

@jarlah
Copy link
Copy Markdown
Member

jarlah commented Apr 17, 2026

Are you ok with squashing? Or do you want to rebase your commits ?

@PedroI920224
Copy link
Copy Markdown
Contributor Author

Yeap I'm OK with squashing

@jarlah jarlah merged commit 055c8ac into testcontainers:main Apr 17, 2026
13 of 14 checks passed
@jarlah
Copy link
Copy Markdown
Member

jarlah commented Apr 17, 2026

Might not release just yet. But you can point to master until i do

@PedroI920224 PedroI920224 deleted the feature/add_mongodb_container branch April 17, 2026 20:30
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