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