title: MongoDB Atlas : MongoCursorTimeoutException (ERROR): : Read timed out after reading 0 bytes, waited for -1.000000 seconds
body: <p>I am trying to shift my mongo cluster to mongodb-atlas.
  When I am trying to connect to mongoDB, it is making the connection(which I can see from atlas logs and php-mongodb driver), but it throws error instantaneously.</p>
  
  <p>I found following in php-driver logs</p>
  
  <pre><code>2018-04-27 02:27:02 :: IO (FINE): getting reply
  2018-04-27 02:27:02 :: IO (FINE): getting cursor header
  2018-04-27 02:27:02 :: CON (FINE): Setting the stream timeout to -1.000000
  2018-04-27 02:27:02 :: MongoCursorTimeoutException (ERROR): &lt;atlashost:port&gt;: Read timed out after reading 0 bytes, waited for -1.000000 seconds`
  </code></pre>
  
  <p>And the same code was running fine, when it was connecting to my own  cluster.</p>
  
  <p>Versions and everything else is same. Version : 3.6</p>
  
  <p>I am stuck in debugging, but can't find anything.</p>
  
  <p>Any help would be appreciated.</p>
  
  <p>Below is the code to show the flow of connection:</p>
  
  <pre><code>final class mongoConnection {
      static function createConnection() {
          $ctx = stream_context_create(array(
              "ssl" =&gt; array(
                  "verify_peer" =&gt; false
              ))
          );
          self::$connection = new MongoClient("mongodb://user:password@host:port/admin&amp;ssl=true",array("replicaSet" =&gt; 'replicaNamw'),array("context" =&gt; $ctx));
          return self::$connection;
      }
  }
  
  function connectMongoDb()
  {
      $mongo = mongoConnection::createConnection();
      $m = $mongo-&gt;getConnection();
      $db = $m-&gt;selectDB('DATABASE');
      return $db;
  }
  
  $mongoDb = $this-&gt;connectMongoDb();
  $collection-&gt;find()-&gt;sort(array('_id' =&gt; -1))-&gt;limit(100); //this is one of the line where I am getting error in my application 
  </code></pre>
  
  <p>Output of <code>var_dump(self::$connection)</code></p>
  
  <pre><code>object(MongoClient)[21]
    public 'connected' =&gt; boolean true
    public 'status' =&gt; null
    protected 'server' =&gt; null
    protected 'persistent' =&gt; null
  </code></pre>
  
  <p>Error :</p>
  
  <pre><code> ( ! ) MongoCursorTimeoutException: &lt;host&gt;:&lt;port&gt;: Read timed out after reading 0 bytes, waited for -1.000000 seconds in &lt;filename&gt; on line 33
  </code></pre>