class

Testcontainers::MongoContainer

Inherits Testcontainers::DockerContainer < Reference < Object

MongoContainer provides a pre-configured container for MongoDB.

Example:

container = Testcontainers::MongoContainer.new
container.start

url = container.connection_url
# => "mongodb://test:test@localhost:32768"

container.stop
container.remove

Constants

MONGO_DEFAULT_DATABASE = "test"
MONGO_DEFAULT_IMAGE = "mongo:latest"
MONGO_DEFAULT_PASSWORD = "test"
MONGO_DEFAULT_PORT = 27017
MONGO_DEFAULT_USERNAME = "test"

Constructors

new(image : String = MONGO_DEFAULT_IMAGE, username : String | Nil = nil, password : String | Nil = nil, database : String = ENV.fetch("MONGO_DATABASE", MONGO_DEFAULT_DATABASE))
Source

Instance methods

connection_url(protocol : String = "mongodb", username : String | Nil = nil, password : String | Nil = nil, database : String | Nil = nil, options : Hash(String, String) = Hash(String, String).new) : String

Returns the MongoDB connection URL.

Source
database
Source
database_url
Source
password
Source
port
Source
start

Starts the container.

This will:

  1. Pull the image if not present
  2. Create the container
  3. Start the container
  4. Execute the wait strategy (if any)

Returns self for method chaining.

Source
username
Source
with_database(database : String) : self
Source
with_password(password : String) : self
Source
with_username(username : String) : self
Source