title: MongoDB Atlas "MongoSocketException Exception sending message"
body: <p>I got this problem when trying to upload an Image to the Atlas database with SpringBoot. When Ido the test on the local MongoDB database, it works well.</p>
  <p>Also My project connected to Atlas well because I can use another api to upload &quot;logo&quot; image, but for my &quot;Image&quot; api, it not working, it prints this:</p>
  <pre><code>2020-11-01 18:04:17.095  WARN 27452 --- [nio-8088-exec-2] org.mongodb.driver.connection            : Got socket exception on connection [connectionId{localValue:4, serverValue:37526}] to cluster0-shard-00-02.1c6kg.mongodb.net:27017. All connections to cluster0-shard-00-02.1c6kg.mongodb.net:27017 will be closed.
  2020-11-01 18:04:17.103  INFO 27452 --- [nio-8088-exec-2] org.mongodb.driver.connection            : Closed connection [connectionId{localValue:4, serverValue:37526}] to cluster0-shard-00-02.1c6kg.mongodb.net:27017 because there was a socket exception raised by this connection.
  2020-11-01 18:04:17.104  INFO 27452 --- [nio-8088-exec-2] org.mongodb.driver.cluster               : No server chosen by WritableServerSelector from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=MULTIPLE, serverDescriptions=[ServerDescription{address=cluster0-shard-00-00.1c6kg.mongodb.net:27017, type=REPLICA_SET_SECONDARY, state=CONNECTED, ok=true, minWireVersion=0, maxWireVersion=8, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=67785768, setName='atlas-d9ovwb-shard-0', canonicalAddress=cluster0-shard-00-00.1c6kg.mongodb.net:27017, hosts=[cluster0-shard-00-00.1c6kg.mongodb.net:27017, cluster0-shard-00-01.1c6kg.mongodb.net:27017, cluster0-shard-00-02.1c6kg.mongodb.net:27017], passives=[], arbiters=[], primary='cluster0-shard-00-02.1c6kg.mongodb.net:27017', tagSet=TagSet{[Tag{name='nodeType', value='ELECTABLE'}, Tag{name='provider', value='GCP'}, Tag{name='region', value='CENTRAL_US'}, Tag{name='workloadType', value='OPERATIONAL'}]}, electionId=null, setVersion=1, lastWriteDate=Sun Nov 01 18:04:13 PST 2020, lastUpdateTimeNanos=124567789557591}, ServerDescription{address=cluster0-shard-00-02.1c6kg.mongodb.net:27017, type=UNKNOWN, state=CONNECTING}, ServerDescription{address=cluster0-shard-00-01.1c6kg.mongodb.net:27017, type=REPLICA_SET_SECONDARY, state=CONNECTED, ok=true, minWireVersion=0, maxWireVersion=8, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=70453359, setName='atlas-d9ovwb-shard-0', canonicalAddress=cluster0-shard-00-01.1c6kg.mongodb.net:27017, hosts=[cluster0-shard-00-00.1c6kg.mongodb.net:27017, cluster0-shard-00-01.1c6kg.mongodb.net:27017, cluster0-shard-00-02.1c6kg.mongodb.net:27017], passives=[], arbiters=[], primary='cluster0-shard-00-02.1c6kg.mongodb.net:27017', tagSet=TagSet{[Tag{name='nodeType', value='ELECTABLE'}, Tag{name='provider', value='GCP'}, Tag{name='region', value='CENTRAL_US'}, Tag{name='workloadType', value='OPERATIONAL'}]}, electionId=null, setVersion=1, lastWriteDate=Sun Nov 01 18:04:13 PST 2020, lastUpdateTimeNanos=124567793068830}]}. Waiting for 30000 ms before timing out
  2020-11-01 18:04:17.273  INFO 27452 --- [ngodb.net:27017] org.mongodb.driver.cluster               : Discovered replica set primary cluster0-shard-00-02.1c6kg.mongodb.net:27017
  2020-11-01 18:04:18.497  INFO 27452 --- [nio-8088-exec-2] org.mongodb.driver.connection            : Opened connection [connectionId{localValue:5, serverValue:41707}] to cluster0-shard-00-02.1c6kg.mongodb.net:27017
  2020-11-01 18:04:19.725  WARN 27452 --- [nio-8088-exec-2] org.mongodb.driver.connection            : Got socket exception on connection [connectionId{localValue:5, serverValue:41707}] to cluster0-shard-00-02.1c6kg.mongodb.net:27017. All connections to cluster0-shard-00-02.1c6kg.mongodb.net:27017 will be closed.
  2020-11-01 18:04:19.726  INFO 27452 --- [nio-8088-exec-2] org.mongodb.driver.connection            : Closed connection [connectionId{localValue:5, serverValue:41707}] to cluster0-shard-00-02.1c6kg.mongodb.net:27017 because there was a socket exception raised by this connection.
  </code></pre>
  <p>This is really wired, why I got this socket exception? I also set the socket-timeout to a large number</p>
  <p>Here is my MongoDB configuration in the application.properties file:
  <code>spring.data.mongodb.uri=mongodb+srv://admin:password@cluster0.1c6kg.mongodb.net/database-name?retryWrites=true&amp;w=majority&amp;connectTimeoutMS=12000&amp;socketTimeoutMS=12000&amp;keepAlive=true </code></p>
  <p>I also check my dependencies, I have:</p>
  <pre><code>        &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-data-mongodb&lt;/artifactId&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.12.7&lt;/version&gt;
          &lt;/dependency&gt;
  </code></pre>
  <p>It's really frustrating, trying to solve this for few hours already. Is there anyway I can configure the Cluster-Shards on Atlas??</p>
  <p>Thanks if someone knowing this problem</p>