title: How to Connect mongodb in node js?
body: <p>I tried to connect mongodb in node js.but its throwing this type error.</p>
  
  <pre><code>Error: getaddrinfo ENOTFOUND mongodb mongodb:27017
  </code></pre>
  
  <p>How to fix it.any one can give me solution</p>
  
  <p>index.js</p>
  
  <p>const MongoClie</p>
  
  <pre><code>nt = require('mongodb').MongoClient;
  var ObjectId = require('mongodb').ObjectID
  const url = "mongodb://olcadmin:olcmongodb@mongodb:27017/admin";
  const client = new MongoClient.connect(url, { useNewUrlParser: true },function(err,db)
  {
      if(err)
      {
          console.log(err)
      }
      else
      {
          console.log("Connected Sucessfully")
      }
  });
  
  
  Connected Successfully  
  </code></pre>
  
  <p>but I got This type error:</p>
  
  <pre><code>{ Error: getaddrinfo ENOTFOUND mongodb mongodb:27017
      at errnoException (dns.js:50:10)
      at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:92:26)
    code: 'ENOTFOUND',
    errno: 'ENOTFOUND',
    syscall: 'getaddrinfo',
    hostname: 'mongodb',
    host: 'mongodb',
    port: 27017 }
  </code></pre>