2

I have used mongoDb with .net I have loaded mongodbdriver core and BSon from visual studio add-in manager for mongodb .net core version 2.2 * Now when i try to create a database and added some collection into it. It has giving me an error like below:

public async void insert(FilePath file)
{
    try
    {
        IMongoCollection<FilePath> collection = _db.GetCollection<FilePath>("FilePath");
        await collection.InsertOneAsync(file);
    }
    catch { };
}

Exception:

A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = WritableServerSelector, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 } }. Client view of cluster state is { ClusterId : "1", ConnectionMode : "Automatic", Type : "Unknown", State : "Disconnected", Servers : [{ ServerId: "{ ClusterId : 1, EndPoint : "Unspecified/localhost:27017" }", EndPoint:

Hamit YILDIRIM
  • 4,224
  • 1
  • 32
  • 35
  • First, you need to replace `async void` to `async Task`. and call `insert` with `await`. – rnofenko Dec 30 '15 at 22:10
  • i tryed all. i think there is some bugs in this version 2.2 after some googling i found the answer in below. thank you – Hamit YILDIRIM Dec 30 '15 at 22:26
  • here the problem is not its async or Task. I Ask you open and clearly about connection timeout. please add comment if you have this type solution... – Hamit YILDIRIM Dec 31 '15 at 10:41
  • Possible duplicate of [MongoDB C# 2.0 TimeoutException](https://stackoverflow.com/questions/29832622/mongodb-c-sharp-2-0-timeoutexception) – kenorb Oct 16 '17 at 16:31

1 Answers1

2

First check the mongo server is running or not.

Possibly you haven't started the Mongo server.

Open a shell and type

mongod

On the file system, you can start it from $MONGO_INSTALL_PATH/bin/mongod.

Don't close the shell and then try to run your code again.

More info:

OR

MongoClient mongo = new MongoClient("localhost", 27017);

But worked out when changed "locahost" to "127.0.0.1"

MongoClient mongo = new MongoClient("127.0.0.1", 27017);
sangram parmar
  • 8,462
  • 2
  • 23
  • 47