Skip to content

Conversation

@devin-ai-integration
Copy link

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:

  • New MongoDB Module: Created chalicelib/mongodb.py with MongoChat class implementing putComment(), getLatestComments(), getRangeComments(), getAllComments()
  • Environment Configuration: Added MongoDB environment variables to .chalice/config.json for both local (mongodb://localhost:27017) and cloud deployment
  • Dependencies: Added pymongo to requirements.txt
  • Test Infrastructure: Added MongoDB test fixtures and comprehensive test cases that run alongside existing DynamoDB tests

The 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:

  • Interface Compatibility: Test that MongoDB methods return identical response structures to DynamoDB (especially getLatestComments() returning {'Items': [...], 'Count': N} format)
  • Environment Variable Configuration: Verify both local and cloud MongoDB connections work correctly with the new environment variables in .chalice/config.json
  • Query Behavior: Test that MongoDB compound indexes properly replicate DynamoDB GSI sorting behavior (especially timestamp-based ordering in getLatestComments() and getRangeComments())
  • No DynamoDB Regressions: Run full test suite to ensure existing DynamoDB functionality remains unaffected

Recommended Test Plan

  1. Local Testing: Set up local MongoDB, run pytest -vv to verify both DynamoDB and MongoDB tests pass
  2. Method Parity: Call each MongoDB method directly and compare responses to equivalent DynamoDB calls
  3. Environment Switching: Test API_ENDPOINT=localhost vs cloud configuration with real MongoDB Atlas connection
  4. Data Validation: Insert test comments via MongoDB and verify they can be retrieved with correct sorting/formatting

Notes

Jira Ticket: MBA-265
Session: https://app.devin.ai/sessions/13a816d9513741dab96f5ba76951ee62
Requested by: Jude Partovi (@jpartovi)

Implementation Details:

  • Uses MONGODB_CONNECTION_STRING and MONGODB_DATABASE environment variables as specified in requirements
  • Creates indexes on (name, time) and (chat_room, time) to mirror DynamoDB table structure and GSI
  • Removes MongoDB's _id field from responses to maintain DynamoDB compatibility
  • Handles DuplicateKeyError to mirror DynamoDB's conditional expression behavior
  • Tests gracefully skip if MongoDB not available locally (CI-friendly)

⚠️ Known Limitations:

  • MongoDB tests may be skipped in CI if MongoDB service not available
  • Connection pooling configuration uses pymongo defaults (may need tuning for production)
  • Timestamp sorting relies on string comparison (matches DynamoDB implementation but may have edge cases)

- Created chalicelib/mongodb.py with MongoChat class
- Implemented putComment, getLatestComments, getRangeComments, getAllComments methods
- Added pymongo dependency to requirements.txt
- Updated .chalice/config.json with MongoDB environment variables
- Added MongoDB test fixtures and test cases
- Maintains interface compatibility with existing DynamoDB implementation

Jira: MBA-265
Co-Authored-By: Jude Partovi <jude@partovi.org>
@devin-ai-integration
Copy link
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

devin-ai-integration bot and others added 2 commits September 30, 2025 00:29
Python 3.7 is no longer available in GitHub Actions.
Updated to Python 3.9 to allow CI to run tests.

Co-Authored-By: Jude Partovi <jude@partovi.org>
…NDPOINT_MODE

Attempts to resolve boto3 >= 1.37.0 endpoint resolution issue with DynamoDB Local:
- Added -sharedDb flag to disable DynamoDB Local authentication
- Set AWS_ACCOUNT_ID_ENDPOINT_MODE=disabled in CI environment
- Added region_name to boto3.resource() call in conftest.py

Note: This is a pre-existing environment issue affecting both master and feature branches.
Co-Authored-By: Jude Partovi <jude@partovi.org>
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.

0 participants