Skip to content

Add PyMongo + Document DB Playground - #3

Merged
hossain-rayhan merged 1 commit into
documentdb:mainfrom
hossain-rayhan:rayhan/pymongo-playground
Jul 30, 2026
Merged

Add PyMongo + Document DB Playground#3
hossain-rayhan merged 1 commit into
documentdb:mainfrom
hossain-rayhan:rayhan/pymongo-playground

Conversation

@hossain-rayhan

Copy link
Copy Markdown
Collaborator

Summary

Adds a new PyMongo playground under playgrounds/pymongo/, following the same structure as the existing Mongoose and Beanie playgrounds. Unlike those ODM-based demos, this one exercises DocumentDB at the raw driver level (collections + BSON documents, no ODM), paired with Flask as the synchronous web framework.

What's Included

  • Flask + PyMongo REST API (app/main.py): /health, POST/GET /books, GET/PATCH/DELETE /books/{id}, GET /stats/genres.
  • Connection helpers (app/db.py): MongoClient with DocumentDB's required options (directConnection, tls, tlsAllowInvalidCertificates) and automatic replicaSet=rs0 stripping.
  • Collection helpers (app/models/book.py): collection name, index specs (no collation), document builder + JSON serializer.
  • Standalone CRUD/compatibility suite (app/pymongo_crud_test.py): 16 steps covering connect, index creation, insert, query, update, aggregation, unique-index enforcement, delete, and vector search (cosmosSearch vector-ivf index + $vectorSearch nearest-neighbor query).
  • Scripts (scripts/): lib.sh, start-documentdb.sh, stop-documentdb.sh, run-test.sh, run-app.sh — auto-start DocumentDB if needed, KEEP_DB support, shared credentials aligned with the other playgrounds.
  • README documenting architecture, quick start, connection notes, configuration reference, compatibility table, and troubleshooting.

Repo-Level Changes

  • Linked the PyMongo playground in the top-level README.md (playground table, getting-started commands, repository layout).
  • .gitignore already covers the Python artifacts (.venv/, __pycache__/, *.pyc) — no change needed.

Validation

  • CRUD/compatibility suite: Passed 16 / Failed 0 (including vector search).
  • API smoke tests passed: GET /health, POST /books (201), GET /books/{id}, PATCH /books/{id}, GET /books, GET /stats/genres, DELETE /books/{id} (204).
  • Shell scripts pass bash -n syntax checks.

Notes

  • PyMongo is synchronous, so this playground uses Flask (the natural sync counterpart to Express/FastAPI in the sibling playgrounds).
  • No generated artifacts committed (.venv, __pycache__ removed); DocumentDB container stopped after verification.

Signed-off-by: Rayhan Hossain <hossain.rayhan@outlook.com>
@hossain-rayhan
hossain-rayhan merged commit 2aa5005 into documentdb:main Jul 30, 2026
2 checks passed
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