title: I am unable to save data to my mongodb Atlas database
body: <p><a href="http://github.com/tahseen09/login" rel="nofollow noreferrer">Github repo.</a> I am trying to use MongoDB Atlas database with my node JS Login &amp; Signup app for storing data. The problem is that the data is not saving to the database or in other words the request isn't going through even if my app is connected to Atlas. Full code available on www.github.com/tahseen09/login</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>// Connection to mongodb atlas
  const uri = "mongodb+srv://tahseen09:&lt;PASSWORD&gt;@cluster0-pirty.mongodb.net/userdb"
  MongoClient.connect(uri, function(err, client) {
     if(err) {
          console.log('Error occurred while connecting to MongoDB Atlas...\n',err);
     }
     console.log('Connected to Atlas');
     const collection = client.db("userdb").collection("credentials");
     client.close();
  });
  
  
  //New User Registration
  
  app.post('/register', function(req,res){
      
      var cred= new credential();
      cred.uname=req.body.uname;
      const hash = bcrypt.hashSync(req.body.password, 10);
      cred.password=hash;
      collection.save(function(err,newuser){
          if(err){
              res.status(500).send("Username exists");
          }
          else{
              res.status(200).send("New User Created");
          }
      })
  })</code></pre>
  </div>
  </div>
  </p>
  
  <p>The code that is important is attached as a snippet and the rest of the code is available on www.github.com/tahseen09/login
  Note: I am running this app on localhost.</p>