title: nodejs application - mongodb connection fails with error "ECONNREFUSED"
body: <p><strong>Background Information</strong></p>
  
  <p>I'm playing around with my first nodejs test app that is attempting to connect to a remote mongodb. </p>
  
  <p><strong>Problem:</strong> </p>
  
  <p>The connection is failing with the following message: </p>
  
  <pre><code>admin@testdev:~/Documents/nodejs_tests$ sudo nodejs index.js
  Server has started.
  Request for / received
  About to route a request for: /
  inside db connect method
  Request for /favicon.ico received
  About to route a request for: /favicon.ico
  inside db connect method
  MongoError: connect ECONNREFUSED
  null
  MongoError: connect ECONNREFUSED
  null
  </code></pre>
  
  <p>Here's the logic to connect: </p>
  
  <pre><code>function connect_nimble() {
          console.log("inside db connect method");
          MongoClient.connect("mongodb://10.1.1.1:27017/test", function(err,db) {
                  console.log(err);
                  console.log(db);
                  if(!err) {
                          console.log("booya!  Connected to mongo");
                          return true;
                  }
          });
  }
  </code></pre>
  
  <p><strong>What I've checked so far:</strong> </p>
  
  <ol>
  <li><p>I've made sure that the database server is using port 27017.  Here's what I see in the mongodb logs when i restart the database: </p>
  
  <pre><code>admin@mongotest:~$ tail -f /var/log/mongodb/mongod.log 
  2015-07-21T09:52:41.452-0500 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
  2015-07-21T09:52:41.452-0500 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
  2015-07-21T09:52:41.452-0500 I CONTROL  [initandlisten] 
  2015-07-21T09:52:41.452-0500 I CONTROL  [initandlisten] db version v3.0.4
  2015-07-21T09:52:41.452-0500 I CONTROL  [initandlisten] git version: 0481c958daeb2969800511e7475dc66986fa9ed5
  2015-07-21T09:52:41.452-0500 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.1f 6 Jan 2014
  2015-07-21T09:52:41.452-0500 I CONTROL  [initandlisten] build info:  Linux ip-10-45-73-23 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49
  2015-07-21T09:52:41.452-0500 I CONTROL  [initandlisten] allocator: tcmalloc
  2015-07-21T09:52:41.452-0500 I CONTROL  [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1" }, storage: { dbPath: "/var/lib/mongodb" }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }
  **2015-07-21T09:52:41.470-0500 I NETWORK  [initandlisten] waiting for connections on port 27017**
  </code></pre></li>
  <li><p>I've made sure I have a database called "test" by starting "mongo"... and then switching in and out of the test database using the "use test" / "use admin" commands. </p></li>
  <li><p>I don't believe I have authorization turned on.  This is what I have in the mongo.conf file: </p></li>
  </ol>
  
  <blockquote>
  <pre><code># Turn on/off security.  Off is currently the default
  #noauth = true
  #auth = true
  </code></pre>
  </blockquote>
  
  <p>And to prove it, in order to get into the test database on the server via command line, I just have to type "mongo" and then by default, I'm in the test database.  So I think I can safely assume I don't have any authentication going on. </p>
  
  <ol start="4">
  <li><p>Just in case, I also checked netstat for the port number: </p>
  
  <p>admin@mongotest:~$ sudo netstat -taupen | grep mongo
  tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN      117        6465150     18792mongod<br>
  admin@mongotest:~$ </p></li>
  </ol>
  
  <p>I'm currently reading the manual to see if there's anything else I should be checking.  I'm also reading through the various stackoverflow posts that are similar, but I haven't found me an answer yet. </p>
  
  <p>Any suggestions? </p>