.Net core connection to mongo db not working

Viewed 1846

I am trying to connect to Mongo DB with .net Core but when calling to the api I get timeout error. I followed this tutorial: https://medium.com/swlh/how-to-use-a-mongodb-database-in-a-asp-net-core-web-api-application-b0451ae314f5

and you can take a look at the full code of this tutorial in this git repo: https://github.com/walpoles93/AspNetCoreMongoDb

I also tried to download this repository and add my user and password of mongo but still same error. The error i get is: System.TimeoutException: A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 } }. Client view of cluster state is { ClusterId : "1", ConnectionMode : "ReplicaSet", Type : "ReplicaSet", State : "Disconnected", Servers : [{ ServerId: "{ ClusterId : 1, EndPoint : "Unspecified/cluster0-shard-00-00.tvnqj.mongodb.net:27017" }", EndPoint: "Unspecified/cluster0-shard-00-00.tvnqj.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.

Has anyone encountered this issue before?

3 Answers

I had a similar issue and the way I managed to solve this was by adding my IP address to the list of allowed Network connections to the Database on the MongoDB cloud dashboard! Network not added

Here is an example of a CRUD operation using ASP.NET Core with Mongo. Below I attach link

You can refer here

It will help you

Related