Task 1.1: Create MongoDB Connection Module - COG-GTM/amazon-dynamodb-chat-sample #8
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.
Task 1.1: Create MongoDB Connection Module - COG-GTM/amazon-dynamodb-chat-sample
Summary
This PR implements Task 1.1 from Jira ticket MBA-265, creating a new MongoDB data access layer that mirrors the existing DynamoDB implementation. The MongoDB module works alongside the existing DynamoDB functionality (does not replace it) and maintains identical method signatures for interface compatibility.
Key Changes:
chalicelib/mongodb.pywithMongoChatclass implementingputComment(),getLatestComments(),getRangeComments(),getAllComments().chalice/config.jsonfor both local (mongodb://localhost:27017) and cloud deploymentpymongotorequirements.txtThe implementation uses the same environment detection pattern (
API_ENDPOINT != 'localhost') to switch between local MongoDB and MongoDB Atlas, and creates compound indexes to replicate DynamoDB's GSI functionality.Review & Testing Checklist for Human
🔴 HIGH RISK - 4 critical items to verify:
getLatestComments()returning{'Items': [...], 'Count': N}format).chalice/config.jsongetLatestComments()andgetRangeComments())Recommended Test Plan
pytest -vvto verify both DynamoDB and MongoDB tests passAPI_ENDPOINT=localhostvs cloud configuration with real MongoDB Atlas connectionNotes
Jira Ticket: MBA-265
Session: https://app.devin.ai/sessions/13a816d9513741dab96f5ba76951ee62
Requested by: Jude Partovi (@jpartovi)
Implementation Details:
MONGODB_CONNECTION_STRINGandMONGODB_DATABASEenvironment variables as specified in requirements(name, time)and(chat_room, time)to mirror DynamoDB table structure and GSI_idfield from responses to maintain DynamoDB compatibilityDuplicateKeyErrorto mirror DynamoDB's conditional expression behavior