feat: Add MongoDB Connection Module (MBA-265) #9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
feat: Add MongoDB Connection Module (MBA-265)
Summary
Implements Task 1.1: Creates a new MongoDB data access layer (
chalicelib/mongodb.py) that mirrors the existing DynamoDB implementation pattern. This PR adds MongoDB support alongside DynamoDB without replacing existing functionality.Key Changes:
chalicelib/mongodb.pywithMongoChatclass implementing 4 methods:putComment,getLatestComments,getRangeComments,getAllCommentspymongodependency torequirements.txt.chalice/config.jsonwith MongoDB environment variables (MONGODB_CONNECTION_STRING,MONGODB_DATABASE)tests/conftest.pyandtests/test_app.pyapp.pyfor future integrationMongoDB Implementation Details:
mongodb://localhost:27017) and MongoDB Atlas via connection stringAPI_ENDPOINTto distinguish between local/cloud (same pattern as DynamoDB)(name, time)and compound(chat_room, time DESC)Review & Testing Checklist for Human
getLatestCommentsreturns dict with 'Items' key, whilegetRangeComments/getAllCommentsreturn lists)create_connectioncreates indexes on every call - consider if this should be done once during deployment insteadapp.py(imports are commented). Consider testing the actual integration by uncommenting imports and switching to MongoDBMONGODB_CONNECTION_STRINGandMONGODB_DATABASEare properly configured in deployment environmentsRecommended Test Plan
docker run -d -p 27017:27017 mongo:latestexport API_ENDPOINT=localhost && export AWS_DEFAULT_REGION=us-east-1 && pytest -vvapp.pyby uncommenting imports and replacing DdbChat usageNotes
datetime.now().timestamp()as part of unique index - extremely unlikely but theoretically possible to have collisions under high load.Jira: MBA-265
Devin Run: https://app.devin.ai/sessions/86f6f5733cfe4618aba7b9be7adecd06
Requested by: Abhay Aggarwal (@abhay-codeium)