def mongo_container() -> Generator[Dict[str, Union[str, Container]], None, None]:
    """Fixture to create a MongoDB container for testing."""
    # Define MongoDB settings
    mongo_image = "mongo:latest"
    mongo_ports = {"27017/tcp": 27017}
    container = None
    try:
        # Initialize Docker client
        client = docker.from_env()

        # Run MongoDB container
        container = client.containers.run(mongo_image, ports=mongo_ports, detach=True)

        # Wait for MongoDB to start
        time.sleep(5)  # Give MongoDB time to initialize

        # Return connection information
        yield {
            "container": container,
            "mongodb_uri": "mongodb://localhost:27017/",
        }
    finally:
        # Stop and remove the container
        if container:
            container.stop()
            container.remove()
            client.close()
Fixture to create a MongoDB container for testing.
llama-index-integrations/storage/chat_store/llama-index-storage-chat-store-mongo/tests/test_chat_store_mongo_chat_store.py