Skip to content

fix(mongodb): add MongoDBAtlasLocalContainer for Atlas Search and Vector Search testing#1010

Open
caseyclements wants to merge 3 commits intotestcontainers:mainfrom
caseyclements:INTPYTHON-922-MongoDBAtlas
Open

fix(mongodb): add MongoDBAtlasLocalContainer for Atlas Search and Vector Search testing#1010
caseyclements wants to merge 3 commits intotestcontainers:mainfrom
caseyclements:INTPYTHON-922-MongoDBAtlas

Conversation

@caseyclements
Copy link
Copy Markdown

New Container

Fixes MongoDB JIRA ticket INTPYTHON-922

Summary

Adds MongoDBAtlasLocalContainer to the existing mongodb module, enabling local testing of MongoDB Atlas-specific features such as Atlas Search and Atlas Vector Search.

The container uses the mongodb/mongodb-atlas-local Docker image, which provides a fully functional local MongoDB Atlas deployment including a single-node replica set and the MongoT search indexing service.

What's included

  • MongoDBAtlasLocalContainer class in modules/mongodb/testcontainers/mongodb/__init__.py
    • Uses ExecWaitStrategy(["runner", "healthcheck"]) for reliable startup detection
    • get_connection_string() returns a mongodb://host:port/?directConnection=true URI
    • get_connection_client() returns a connected pymongo.MongoClient
  • Tests in modules/mongodb/tests/test_mongodb.py
    • Basic CRUD test (test_docker_run_mongodb_atlas_local)
    • Connection string format test (test_mongodb_atlas_local_connection_string)
    • Vector search integration test (test_vector_search) — creates a vector index, waits for indexing, and queries with $vectorSearch
  • README.rst updated with MongoDBAtlasLocalContainer autoclass directive

PR Checklist

  • Your PR title follows the Conventional Commits syntax
    • Suggested title: fix(mongodb): add MongoDBAtlasLocalContainer for Atlas Search and Vector Search testing
  • Your PR allows maintainers to edit your branch, this will speed up resolving minor issues!
  • The new container is implemented under modules/*
    • Added to existing modules/mongodb module (not a new module)
    • Package namespacing follows testcontainers.mongodb.*
    • No __init__.py above module level
    • Tests under modules/mongodb/tests
    • README.rst updated
  • Your module is added in pyproject.toml
    • Already declared — this extends the existing mongodb module
    • No new dependencies — uses existing pymongo>=4 optional dependency

Preferred implementation

This implementation follows the maintainer preference of minimal dependencies:

  • No additional client libraries — uses pymongo which is already an optional dependency of the mongodb module
  • Startup wait strategy — uses ExecWaitStrategy(["runner", "healthcheck"]) (matching the health check approach used by testcontainers-java's Atlas module) rather than log-based detection
  • The vector search test uses a simple hashlib-based mock embedding function — no numpy or ML library dependencies

Add a testcontainer for MongoDB Atlas Local (mongodb/mongodb-atlas-local),
which provides a local Atlas environment with Atlas Search and Vector Search.

- Extends DockerContainer directly (no auth required)
- Uses ExecWaitStrategy with 'runner healthcheck' for readiness
- Connection string includes directConnection=true
- Includes integration tests for insert/query and connection string format
…alContainer

- Add test_vector_search using deterministic hash-based mock embeddings
- indexed_collection fixture: inserts docs, creates vector index, polls
  until all documents are indexed (handles OperationFailure during init)
- Asserts top_k limiting, exact-match ranking, and score range

Signed-off-by: Casey Clements <casey.clements@mongodb.com>
- Add autoclass directive in modules/mongodb/README.rst
- Update docs/modules/mongodb.md to describe both container classes

Signed-off-by: Casey Clements <casey.clements@mongodb.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant