# `Testcontainers.MongoContainer`
[🔗](https://github.com/testcontainers/testcontainers-elixir/blob/main/lib/container/mongo_container.ex#L2)

Provides functionality for creating and managing Mongo container configurations.

# `t`

```elixir
@type t() :: %Testcontainers.MongoContainer{
  check_image: term(),
  database: term(),
  image: term(),
  password: term(),
  persistent_volume: term(),
  port: term(),
  reuse: term(),
  user: term(),
  wait_timeout: term()
}
```

# `connection_parameters`

Returns the connection parameters to connect to the database from the _host machine_.

# `database_url`

Alias for `mongo_url/2`.

# `default_image`

Retrieves the default Docker image for the Mongo container.

# `default_image_with_tag`

Retrieves the default Docker image including tag for the Mongo container.

# `default_port`

Retrieves the default exposed port for the Mongo container.

# `mongo_url`

Generates the MongoDB connection URL.

## Options
  * `:protocol` - URL scheme, defaults to `"mongodb"`.
  * `:username` - Overrides username from container env.
  * `:password` - Overrides password from container env.
  * `:database` - Overrides database from container env.
  * `:options` - Query options as map/keyword list.

# `new`

Creates a new `MongoContainer` struct with default configurations.

# `port`

Returns the port on the _host machine_ where the Mongo container is listening.

# `with_check_image`

Set the regular expression to check the image validity.

# `with_database`

Overrides the default database used for the Mongo container.

## Examples

    iex> config = MongoContainer.new()
    iex> new_config = MongoContainer.with_database(config, "another-database")
    iex> new_config.database
    "another-database"

# `with_image`

Overrides the default image used for the Mongo container.

## Examples

    iex> config = MongoContainer.new()
    iex> new_config = MongoContainer.with_image(config, "mongo:5")
    iex> new_config.image
    "mongo:5"

# `with_password`

Overrides the default password used for the Mongo container.

## Examples

    iex> config = MongoContainer.new()
    iex> new_config = MongoContainer.with_password(config, "another-password")
    iex> new_config.password
    "another-password"

# `with_persistent_volume`

mounts persistent volume in Mongo data path used for the Mongo container.

## Examples

    iex> config = MongoContainer.new()
    iex> config = MongoContainer.with_persistent_volume(config, "data_volume")
    iex> config.persistent_volume
    "data_volume"

# `with_port`

Overrides the default port used for the Mongo container.

Note: this will not change what port the docker container is listening to internally.

## Examples

    iex> config = MongoContainer.new()
    iex> new_config = MongoContainer.with_port(config, 27018)
    iex> new_config.port
    27018

# `with_reuse`

Set the reuse flag to reuse the container if it is already running.

# `with_user`

Overrides the default user used for the Mongo container.

## Examples

    iex> config = MongoContainer.new()
    iex> new_config = MongoContainer.with_user(config, "another-user")
    iex> new_config.user
    "another-user"

# `with_username`

Alias for `with_user/2`, matching Mongo naming in other implementations.

# `with_wait_timeout`

Mounts the default wait timeout used for the Mongo container.

Note: this timeout will be used for each individual wait strategy.

## Examples

    iex> config = MongoContainer.new()
    iex> new_config = MongoContainer.with_wait_timeout(config, 8000)
    iex> new_config.wait_timeout
    8000

---

*Consult [api-reference.md](api-reference.md) for complete listing*
