title: Mongoose error: The uri parameter to openuri() must be string, got "object". Make sure the first parameter to mongoose.connect() is a string
body: <p>Why am I getting this error if i have connected to databases before this way? </p>
  
  <p>Here is my code:</p>
  
  <pre><code>const express = require('express');
  const router = express.Router();
  const mongoose = require('mongoose');
  const Player = require('../models/player');   //import player database  
  
  const db = mongoose.connect('mongodb://user:pass@ds263493.mlab.com:63493/user', { useNewUrlParser: true });
  mongoose.Promise = global.Promise; //Promise type avoids warnings mongoose throws
  mongoose.connect(db, function(err)
  {
      if(err){
          console.error("Error! "+ err);
      }
  });
  
  router.get('/players', function(req, res)               //make req to players
  {
      console.log('Get request for all players');
      Player.find({})                                     //connected to players collection in database
      .exec(function(err, players)                        //once players are found, send as response to browser
      {
          if(err)
          {
              console.log("Error retrieving players");
          }
          else
          {
              res.json(players);
          }
      })
  });
  
  module.exports = router;
  </code></pre>
  
  <p>I changed the username and password for database to default, just for this question, that is not the problem. </p>
  
  <p>Somehow it is saying the parameter for mongoose.connect("") is not a string when it is, i even tried useNewUrlParser:true, but it is still giving me same error. </p>