Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have created mongo db and trying to call collection in asp.net core web api
i am getting the below exception
A timeout occurred 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 : [] }.


Could you please assist how to get mongodb collection documents by id or any field the mapping class is ready to map that document data.

What I have tried:

I have tried with the below code which is working in Robot3t
<pre>        string ConnectionString = "mongodb+srv://myadmin:ChekTesting@123@clus12-srd123-878-87.filik54so.mongodb.net/MyDataBase?connect=replicaSet&connectTimeoutMS=60000&socketTimeoutMS=60000";

public  ServiceResponse GetUserServiceDetails(string userId)
        {

             ServiceResponse obj ServiceResponse = new  ServiceResponse();

            try
            {
                List<UserServiceViewModel> objUserServiceViewModel = new List<UserServiceViewModel>();
                var mongoClient = new MongoClient(ConnectionString);
                var rdgvr4uDatabase = mongoClient.GetDatabase("MyDatabase");
                var userServiceCollection = rdgvr4uDatabase.GetCollection<UserServiceViewModel>("UserServiceCollection");
                object datId = new ObjectId("605653cde5d0452fabd47b24");
                objUserServiceViewModel = userServiceCollection.Find(us => us._id == datId).ToList();
            }
            catch (Exception ex)
            {
                obj ServiceResponse.ErrorCode = 1;
                obj ServiceResponse.ErrorMessage = ex.Message;
            }
            return obj ServiceResponse;
        }



Could you please assist on this how to call mongodb documents in webapi. Did i missed any thing is required in asp.net core
Posted
Updated 22-Mar-21 20:28pm
Comments
SeanChupas 22-Mar-21 15:38pm    
If you cannot connect to the db what can we do?

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900