Azure Function App: Not connecting to mongodb

Prakhar Sinha 36 Reputation points
2020-11-16T18:54:52.01+00:00

I have set up an azure function app that connects to a mongodb database(cloud service: https://www.mongodb.com/cloud/atlas)
The code runs fine on local but I get a Result: Failure Exception: ServerSelectionTimeoutError error continously when its deployed as a function app.
I have whitelisted app possible outbound IP addresses, the service did not even work with 0.0.0.0 configured on Mongodb atlas. Mongodb support thinks the problem is on the Azure side.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,670 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MayankBargali-MSFT 70,011 Reputation points
    2020-11-17T06:02:09.09+00:00

    Hi @Prakhar Sinha

    Welcome to Microsoft Q&A! Thanks for posting the question.

    Can you please confirm what is the hosting plan for your function app and what IP's you have whitelisted at the MongoDB end? Azure Functions has dedicated IPs only in certain hosting models, see here for details.

    As per the error you need to make sure that the function app IP is whitelisted. Some hosting models do not provide a static IP, so you need to whitelist the datacenter IP for the region where your function app is deployed. You can find the datacenter IP's here.