title: MongoDB How to fix: Error: couldn't connect to server 197.0.196.205:27017, connection attempt failed: SocketException
body: <p>I'm trying to connect remotely on a mongodb server throw my local machine, but i'm having some issues.</p>
  
  <p>On the remote server i modified the 'mongod.cfg' file and i changed the bindIp from 127.0.0.1 to 0.0.0.0 to allow access. In the same file i changed the security by adding Authentication: 'enabled'.</p>
  
  <p>I created an admin user:</p>
  
  <pre><code>&gt; use admin
  &gt; db.createUser({user: "root", pwd: "root", roles:["root"]})
  </code></pre>
  
  <p>I started mongodb with --auth flag </p>
  
  <pre><code>&gt; mongod --auth --port 27017
  </code></pre>
  
  <p>Once the server was up, i connect to it as administrator</p>
  
  <pre><code>mongo 127.0.0.1:27017 -u "root" -p "root" --authenticationDatabase "admin"
  </code></pre>
  
  <p>Once i was connected, i created a normal user</p>
  
  <pre><code>&gt; use base
  &gt; db.createUser({user: "base", pwd: "base", roles:["dbOwner"]})
  </code></pre>
  
  <p>Then i disconnected from mongo shell and reconnected with new user credentials</p>
  
  <pre><code>&gt; mongo 127.0.0.1/base -u "base" -p "base"
  </code></pre>
  
  <p>It worked properly on the remote server.</p>
  
  <p>On the local machine i tried: </p>
  
  <pre><code>&gt; mongo &lt;ip address of the server&gt;/base -u "base" -p "base"
  </code></pre>
  
  <p>I'm getting this error:</p>
  
  <pre><code>&gt; mongo &lt;ip address&gt;:27017/base -u "base" -p "base"
  [js] Error: couldn't connect to server &lt;ip address&gt;:27017, connection attempt failed: SocketException: Error connecting to &lt;ip address&gt;:27017 :: caused by :: Operation timed out :
  connect@src/mongo/shell/mongo.js:344:17
  @(connect):2:6
  exception: connect failed
  
  </code></pre>