Testcontainers.MongoContainer (testcontainers v2.3.1)

Copy Markdown View Source

Provides functionality for creating and managing Mongo container configurations.

Summary

Functions

Returns the connection parameters to connect to the database from the host machine.

Retrieves the default Docker image for the Mongo container.

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

Retrieves the default exposed port for the Mongo container.

Generates the MongoDB connection URL.

Creates a new MongoContainer struct with default configurations.

Returns the port on the host machine where the Mongo container is listening.

Set the regular expression to check the image validity.

Overrides the default database used for the Mongo container.

Overrides the default image used for the Mongo container.

Overrides the default password used for the Mongo container.

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

Overrides the default port used for the Mongo container.

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

Overrides the default user used for the Mongo container.

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

Mounts the default wait timeout used for the Mongo container.

Types

t()

@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()
}

Functions

connection_parameters(container)

Returns the connection parameters to connect to the database from the host machine.

database_url(container, opts \\ [])

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(container, opts \\ [])

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(container)

Returns the port on the host machine where the Mongo container is listening.

with_check_image(config, check_image)

Set the regular expression to check the image validity.

with_database(config, 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(config, 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(config, 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(config, 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(config, 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(config, reuse)

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

with_user(config, 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(config, username)

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

with_wait_timeout(config, 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