title: How to fix: Error: couldn't connect to server <ip address>:27017, connection attempt failed: Connection refused
body: <p>I'm running mongodb on a remote server and I want to access within my local machine</p>
  
  <p>I've tried to remove the mongodb.lock file, also tried <code>sudo mongod --repair</code> but none of these worked for me.</p>
  
  <p>This happens when I'm doing <code>mongo &lt;ip address&gt;:27017/testDB</code> or simply <code>mongo &lt;ip address&gt;</code> </p>
  
  <p>I'm getting:</p>
  
  <pre><code>[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 :: Connection refused :
  connect@src/mongo/shell/mongo.js:344:17
  @(connect):2:6
  exception: connect failed  
  
  </code></pre>
  
  <p>The mongo.cfg file looks like this:</p>
  
  <pre><code># mongod.conf
  
  # for documentation of all options, see:
  #   http://docs.mongodb.org/manual/reference/configuration-options/
  
  # Where and how to store data.
  storage:
    dbPath: C:\Program Files\MongoDB\Server\4.0\data
    journal:
      enabled: true
  #  engine:
  #  mmapv1:
  #  wiredTiger:
  
  # where to write logging data.
  systemLog:
    destination: file
    logAppend: true
    path:  C:\Program Files\MongoDB\Server\4.0\log\mongod.log
  
  # network interfaces
  net:
    port: 27017
    bindIp: 0.0.0.0
  
  
  #processManagement:
  
  #security:
    authorization: 'enabled'
  
  #operationProfiling:
  
  #replication:
  
  #sharding:
  
  ## Enterprise-Only Options:
  
  #auditLog:
  
  #snmp:
  </code></pre>