title: MongoDB Remote connection with php
body: <p>Deployed a quick cloud server just to host a MongoDB to tinker with it out of curiosity. It's installed and works. Made a test DB/Table like this:</p>
  
  <pre><code> db.items.insert({ name: 'eggs', quantity: 10, price: 1.50 })
   db.items.insert({ name: 'bacon', quantity: 3, price: 3.50 })
   db.items.insert({ name: 'tomatoes', quantity: 30, price: 0.50 })
  </code></pre>
  
  <p>When I run <code>db.items.find({})</code> all the items appear and all is well.</p>
  
  <p>Now in PHP when I connect to that database from a different server I do this:</p>
  
  <pre><code>  // open connection to MongoDB server
    $conn = new Mongo('mongodb://theAdmin:Gold1234@165.225.130.252:27017');
  
    // access database
    $db = $conn-&gt;test;
  
    // access collection
    $collection = $db-&gt;items;
  
    // execute query
    // retrieve all documents
    $cursor = $collection-&gt;find();
  
    // iterate through the result set
    // print each document
    echo $cursor-&gt;count() . ' document(s) found. &lt;br/&gt;';  
    foreach ($cursor as $obj) {
      echo 'Name: ' . $obj['name'] . '&lt;br/&gt;';
      echo 'Quantity: ' . $obj['quantity'] . '&lt;br/&gt;';
      echo 'Price: ' . $obj['price'] . '&lt;br/&gt;';
      echo '&lt;br/&gt;';
    }
  </code></pre>
  
  <p>and I get this error:</p>
  
  <blockquote>
    <p>Fatal error: Uncaught exception 'MongoConnectionException' with
    message 'Failed to connect to: 165.225.130.252:27017: Transport
    endpoint is not connected' in /home/moosex/public_html/info.php:4
    Stack trace: #0 /home/moosex/public_html/info.php(4):
    Mongo->__construct('mongodb://[theA...') #1 {main} thrown in
    /home/moosex/public_html/info.php on line 4</p>
  </blockquote>
  
  <p>I've looked up and tried several different ways to connect and still can't get it. How am I supposed to connect remotely? </p>
  
  <p>BTW, that is the actual username password and address to that server(there's nothing on there except for eggs bacon and tomatoes), if you can connect to it, god bless you lol.</p>