getcursor / cursor

The AI-powered code editor
https://cursor.sh
20.57k stars 1.38k forks source link

Connection to MongoDB Not working #1450

Closed mikahoy045 closed 1 month ago

mikahoy045 commented 1 month ago

1) If you can, please include a screenshot of your problem image

using pycharm for same code, no problem

image

`from fastapi import HTTPException from motor.motor_asyncio import AsyncIOMotorClient from starlette.status import HTTP_503_SERVICE_UNAVAILABLE from dotenv import load_dotenv import os

load_dotenv() # Load environment variables

MONGO_URI = os.getenv("MONGO_URI") # Make sure this matches your .env variable name MONGO_DB = os.getenv("MONGO_DB") client = None

def get_database(): global client if client is None: # Only create a client if it doesn't already exist try: client = AsyncIOMotorClient(MONGO_URI) except Exception as e: raise HTTPException(status_code=HTTP_503_SERVICE_UNAVAILABLE, detail="Could not connect to the database") from e return client[MONGO_DB] # Replace 'mydatabase' with your actual database name `

2) Please include the name of your operating system Ubuntu 20.04 3) If you can, steps to reproduce are super helpful Nothing, just code and run it, this code should connect to mongodb , but it's not. Testing with same code (access same repository) from another IDE it works, no problem. And Yes, I have setup the environment also

mikahoy045 commented 1 month ago

So funny that to solve this I need to source .env so that cursor can read my .env file. It's just works by using other IDE like pycharm.