2

I just created an Azure Function that should connect to my instance of MongoDB on Atlas, basically following this tutorial:

https://www.mongodb.com/blog/post/how-to-integrate-azure-functions-with-mongodb

From my local development with Visual Studio, everything works fine and I can connect to the Atlas environment, but when I deploy the code on Azure, the following exception raises:

A timeout occurred after 30000ms selecting a server using CompositeServerSelector{ Selectors = MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 }, OperationsCountServerSelector }. Client view of cluster state is { ClusterId : "1", ConnectionMode : "ReplicaSet", Type : "ReplicaSet", State : "Disconnected", Servers : [{ ServerId: "{ ClusterId : 1, EndPoint : "Unspecified/ltdevcluster-shard-00-00.qkeby.mongodb.net:27017" }", EndPoint: "Unspecified/ltdevcluster-shard-00-00.qkeby.mongodb.net:27017", ReasonChanged: "Heartbeat", State: "Disconnected", ServerVersion: , TopologyVersion: , Type: "Unknown", HeartbeatException: "MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. ---> MongoDB.Driver.MongoConnectionException: An exception occurred while receiving a message from the server. ---> System.IO.EndOfStreamException: Attempted to read past the end of the stream.

If I instead set the Network Access to "everywhere", again everything works fine.

Now, in the Network Access panel of Atlas, I added the IPs retrieved from the Azure Portal under my function app => Networking => Inbound traffic and Outbound traffic (a total of 1 IP for inbound and 3 IPs for outbound).

But adding those 4 IPs has not solved the issue.

What else should I do?

0

1 Answer 1

1

If you are using static IP, for a workaround, you can check this: How do I set a static IP in Functions?

You can also set up a Private Endpoint and for the security of the database credentials check secrets engine integration using vault.

You can refer to How to connect Azure Function with MongoDB Atlas ,Azure functions unable to connect with Mongo Db Atlas M10 and How to connect Azure Function with MongoDB Atlas

Sign up to request clarification or add additional context in comments.

4 Comments

Hi @DeepDave-MT, if I understood correctly, these options are available for the premium plans. Is there a way to do that with the Free tier? i.e. Atlas M0 Sandbox?
Yes, you can do it with a free tier with some limitations. You can refer to MongoDB Atlas free on Azure and Atlas M0 (Free Cluster) Limitations
So the answer to my question is basically "No, you cannot do this connection using the M0 free tier"?
Yes, only possible with some Configuration Limitations

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.