Hamit YILDIRIM
Hamit YILDIRIM

Reputation: 4539

.net mongodb version 2.2 timeout exception

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:

Upvotes: 2

Views: 3525

Answers (1)

sangram parmar
sangram parmar

Reputation: 8726

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);

Upvotes: 2

Related Questions