MongoDB connection from cloud functions

I am trying to create MongoDB connection from google cloud functions.

this is what I am doing to establish connection await MongoClient.connect(uri). I have already set up VPC peering and the status is available. I also added to the whitelist. However, when I call the cloud function, I am getting

MongoServerSelectionError: Client network socket disconnected before secure TLS connection was established at Timeout...

I also added vpc to cloud function that I am calling with Allow all traffic for ingress and Route only requests to private IPs through the VPC connector to egress

What can I do to fix this issue?

Hey, welcome to the MongoDB community, it will be a pleasure to help you.

Did you get the URI directly from the panel? Can you show how you put it together?

Hi, I am using the uri in form of

And I am able to connect to it locally

Basically, to use cloud function with Atlas it is necessary to have the vpc configured in Atlas (peering) and the release in the project’s IP access list.