class MongoDbContainer(image: str = 'mongo:latest', port_to_expose: int = 27017, **kwargs)ΒΆ

Mongo document-based database container.

Example

>>> from testcontainers.mongodb import MongoDbContainer

>>> with MongoDbContainer("mongo:latest") as mongo:
...    db = mongo.get_connection_client().test
...    # Insert a database entry
...    result = db.restaurants.insert_one(
...        {
...            "address": {
...                "street": "2 Avenue",
...                "zipcode": "10075",
...                "building": "1480",
...                "coord": [-73.9557413, 40.7720266]
...            },
...            "borough": "Manhattan",
...            "cuisine": "Italian",
...            "name": "Vella",
...            "restaurant_id": "41704620"
...        }
...    )
...    # Find the restaurant document
...    cursor = db.restaurants.find({"borough": "Manhattan"})