diff --git a/.chalice/config.json b/.chalice/config.json index 45a85e5..62c8ff4 100644 --- a/.chalice/config.json +++ b/.chalice/config.json @@ -7,13 +7,15 @@ "local": { "api_gateway_stage": "api", "environment_variables": { - "API_ENDPOINT": "localhost" + "API_ENDPOINT": "localhost", + "MONGODB_URI": "mongodb://localhost:27017" } }, "dev": { "environment_variables": { - "API_ENDPOINT": "https://your_API_ENDPOINT" + "API_ENDPOINT": "https://your_API_ENDPOINT", + "MONGODB_URI": "mongodb://localhost:27017" } } } -} \ No newline at end of file +} diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..787c07d --- /dev/null +++ b/.env.example @@ -0,0 +1,6 @@ +# MongoDB Configuration +# Local MongoDB URI for development +MONGODB_URI=mongodb://localhost:27017 + +# API Endpoint (existing DynamoDB configuration) +API_ENDPOINT=localhost diff --git a/requirements.txt b/requirements.txt index fecb744..b755505 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,5 @@ chalice flake8 moto pytest-chalice -pytest-env \ No newline at end of file +pytest-env +pymongo>=4.0.0 diff --git a/test_mongodb_connection.py b/test_mongodb_connection.py new file mode 100644 index 0000000..37c9944 --- /dev/null +++ b/test_mongodb_connection.py @@ -0,0 +1,22 @@ +import pymongo +import sys + +try: + client = pymongo.MongoClient('mongodb://localhost:27017', serverSelectionTimeoutMS=5000) + client.admin.command('ping') + print("✓ Successfully connected to MongoDB") + + db = client['chat'] + collection = db['chat'] + + result = collection.find_one() + print(f"✓ Successfully accessed chat database and collection") + print(f"✓ Found document: {result}") + + client.close() + print("\n✓ All MongoDB connectivity tests passed!") + sys.exit(0) + +except Exception as e: + print(f"✗ MongoDB connection failed: {e}") + sys.exit(1)