I was expecting to run the function normally, being able to connect to the database, but it keeps returning Server selection errors, I've tried using both localhost and 172.17.0.2 (which is the docker inspect result), and it simply won't connect. The issue isn't the database as I can connect to it just fine through both localhost and 172.17.0.2.
I have added the MONGO_URL env var to the local.settings.json, and it is being grabbed since it says it failed to connect to the right IP
env = os.getenv("MONGO_URL")
client = pymongo.MongoClient(env)
db = client["data"]
col = db["objects"]
Also, weirdly enough, I've tried to print stuff before the client invocation when I was trying to debug it, and the connection would run before the print statements, even though they were placed before the connection
[2023-05-31T16:04:33.213Z] Executed 'Functions.HttpTrigger1' (Failed, Duration=30422ms)
[2023-05-31T16:04:33.213Z] System.Private.CoreLib: Exception while executing function: Functions.HttpTrigger1. System.Private.CoreLib: Result: Failure
[2023-05-31T16:04:33.213Z] Exception: ServerSelectionTimeoutError: 172.17.0.2:27017: timed out, Timeout: 30s, Topology Description: <TopologyDescription topology_type: Unknown, servers: [<ServerDescription ('172.17.0.2', 27017) server_type: Unknown, rtt: None, error=NetworkTimeout('172.17.0.2:27017: timed out')>]>
I think it's fine, but just in case, here's my local.settings.json
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "python",
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"AzureWebJobsFeatureFlags": "EnableWorkerIndexing",
"MONGO_URL": "mongodb://172.17.0.2:27017"
}
}