title: timed out after 30000 ms while waiting for a server that matches WritableServerSelector
body: <p>I have seen this problem at many forums but none of them resolved my issue. I am trying to insert a sample document to MongoDB DB. Unfortunately, during the insert process <code>colReceived.insert(doc)</code> I got following error:</p>
  
  <blockquote>
    <p>SEVERE: Servlet.service() for servlet spring threw exception
    com.mongodb.MongoTimeoutException: Timed out after 30000 ms while
    waiting for a server that matches WritableServerSelector. Client view
    of cluster state is {type=UNKNOWN, servers=[{address=localhost:27017,
    type=UNKNOWN, state=CONNECTING,
    exception={com.mongodb.MongoSocketOpenException: Exception opening
    socket}, caused by {java.net.ConnectException: Connection refused:
    connect}}]    at
    com.mongodb.connection.BaseCluster.createTimeoutException(BaseCluster.java:369)</p>
  </blockquote>
  
  <p>Here is my connectToDb method </p>
  
  <pre><code>   MongoClient mongoClient = new MongoClient();
  
      // Now connect to your database
      DB db = mongoClient.getDB("test");
      System.out.println("connect to database successfully");
  
      DBCollection coll = db.createCollection("mycol", null);
      System.out.println("Collection created successfully");
  
      DBCollection colReceived = db.getCollection("mycol");
      System.out.println("Collection mycol selected successfully");
  
      BasicDBObject doc = new BasicDBObject("title", "MongoDB").append("description", "database").append("likes", 100)
              .append("url", "http://www.tutorialspoint.com/mongodb/").append("by", "tutorials point");
  
      colReceived.insert(doc);
      System.out.println("Document inserted successfully");
  </code></pre>
  
  <p>My pom.xml :</p>
  
  <pre><code>  &lt;project xmlns="http://maven.apache.org/POM/4.0.0"      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
  http://maven.apache.org/maven-v4_0_0.xsd"&gt;
  
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  &lt;groupId&gt;com.objectdb.tutorial.spring&lt;/groupId&gt;
  &lt;artifactId&gt;Guestbook&lt;/artifactId&gt;
  &lt;packaging&gt;war&lt;/packaging&gt;
  &lt;version&gt;1.0&lt;/version&gt;
  &lt;name&gt;Guestbook&lt;/name&gt;
  &lt;url&gt;http://maven.apache.org&lt;/url&gt;
  &lt;properties&gt;
      &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
  &lt;/properties&gt;
  
  &lt;repositories&gt;
      &lt;repository&gt;
          &lt;id&gt;objectdb&lt;/id&gt;
          &lt;name&gt;ObjectDB Repository&lt;/name&gt;
          &lt;url&gt;http://m2.objectdb.com&lt;/url&gt;
      &lt;/repository&gt;
  &lt;/repositories&gt;
  
  &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.objectdb&lt;/groupId&gt;
          &lt;artifactId&gt;objectdb&lt;/artifactId&gt;
          &lt;version&gt;2.6.2&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.eclipse.persistence&lt;/groupId&gt;
          &lt;artifactId&gt;javax.persistence&lt;/artifactId&gt;
          &lt;version&gt;2.1.0&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.transaction&lt;/groupId&gt;
          &lt;artifactId&gt;jta&lt;/artifactId&gt;
          &lt;version&gt;1.1&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
          &lt;artifactId&gt;servlet-api&lt;/artifactId&gt;
          &lt;version&gt;2.5&lt;/version&gt;
          &lt;scope&gt;provided&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.servlet.jsp&lt;/groupId&gt;
          &lt;artifactId&gt;jsp-api&lt;/artifactId&gt;
          &lt;version&gt;2.1&lt;/version&gt;
          &lt;scope&gt;provided&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
          &lt;version&gt;3.0.5.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-tx&lt;/artifactId&gt;
          &lt;version&gt;3.0.5.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-orm&lt;/artifactId&gt;
          &lt;version&gt;3.0.5.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;aopalliance&lt;/groupId&gt;
          &lt;artifactId&gt;aopalliance&lt;/artifactId&gt;
          &lt;version&gt;1.0&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;cglib&lt;/groupId&gt;
          &lt;artifactId&gt;cglib&lt;/artifactId&gt;
          &lt;version&gt;2.2&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.aspectj&lt;/groupId&gt;
          &lt;artifactId&gt;aspectjweaver&lt;/artifactId&gt;
          &lt;version&gt;1.6.10&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
      &lt;groupId&gt;org.mongodb&lt;/groupId&gt;
      &lt;artifactId&gt;mongo-java-driver&lt;/artifactId&gt;
      &lt;version&gt;3.2.2&lt;/version&gt;
  &lt;/dependency&gt;
  
  
  &lt;/dependencies&gt;
  
  &lt;build&gt;
      &lt;pluginManagement&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;configuration&gt;
                      &lt;source&gt;1.7&lt;/source&gt;
                      &lt;target&gt;1.7&lt;/target&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
                  &lt;artifactId&gt;exec-maven-plugin&lt;/artifactId&gt;
                  &lt;version&gt;1.2&lt;/version&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;id&gt;enhance&lt;/id&gt;
                          &lt;phase&gt;process-classes&lt;/phase&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;java&lt;/goal&gt;
                          &lt;/goals&gt;
                          &lt;configuration&gt;
                              &lt;mainClass&gt;com.objectdb.Enhancer&lt;/mainClass&gt;
                              &lt;arguments&gt;
                                  &lt;argument&gt;guest.Guest&lt;/argument&gt;
                              &lt;/arguments&gt;
                          &lt;/configuration&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.mortbay.jetty&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-jetty-plugin&lt;/artifactId&gt;
                  &lt;version&gt;6.1.10&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;scanIntervalSeconds&gt;10&lt;/scanIntervalSeconds&gt;
                      &lt;stopKey&gt;foo&lt;/stopKey&gt;
                      &lt;stopPort&gt;9999&lt;/stopPort&gt;
                  &lt;/configuration&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;id&gt;start-jetty&lt;/id&gt;
                          &lt;phase&gt;pre-integration-test&lt;/phase&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;run&lt;/goal&gt;
                          &lt;/goals&gt;
                          &lt;configuration&gt;
                              &lt;scanIntervalSeconds&gt;0&lt;/scanIntervalSeconds&gt;
                              &lt;daemon&gt;true&lt;/daemon&gt;
                          &lt;/configuration&gt;
                      &lt;/execution&gt;
                      &lt;execution&gt;
                          &lt;id&gt;stop-jetty&lt;/id&gt;
                          &lt;phase&gt;post-integration-test&lt;/phase&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;stop&lt;/goal&gt;
                          &lt;/goals&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/pluginManagement&gt;
      &lt;finalName&gt;Guestbook&lt;/finalName&gt;
  &lt;/build&gt;
  </code></pre>
  
  <p></p>