title: Authentication always failing when connecting to MongoDB
body: <p>I am using node/express
     node_modules =
      "mongodb": "2.0.33",
      "mongoose": "3.8.15",</p>
  
  <p>mongo shell version: 3.0, and mongo 3.0</p>
  
  <p>I'm able to connect to my mongoDB just fine, but if I pass in any authentication parameters, it will fail:  </p>
  
  <pre><code>connection error: { [MongoError: auth failed] name: 'MongoError', ok: 0, errmsg: 'auth failed', code: 18 }
  </code></pre>
  
  <p>The following shows up in the logs when this happens: </p>
  
  <pre><code>2015-06-13T15:10:09.863-0400 I ACCESS [conn8] authenticate db: mydatabase { authenticate: 1, user: "user", nonce: "xxx", key: "xxx" } 2015-06-13T15:10:09.863-0400 I ACCESS [conn8] Failed to authenticate user@mydatabase with mechanism MONGODB-CR: AuthenticationFailed UserNotFound Could not find user user@mydatabase
  </code></pre>
  
  <p>I've done quite a few patterns to try to get this to work.</p>
  
  <p>Here's what happens when I do the show users command in the mongo shell while on the appropriate database:  </p>
  
  <pre><code>{
      "_id" : "mydatabase.user",
      "user" : "user",
      "db" : "mydatabase",
      "roles" : [
          {
              "role" : "readWrite",
              "db" : "mydatabase"
          }
      ]
  }
  </code></pre>
  
  <p>Here's my attempt to connect to this particular database while passing in the correct parameters:  </p>
  
  <pre><code>mongoose.connect('mongodb://user:password@host:port/mydatabase');
  </code></pre>
  
  <p>For good measure I also tried passing in an options hash instead of passing the params via uri:  </p>
  
  <pre><code>mongoose.connect('mongodb://host:port/mydatabase',{user: 'user',pass: 'password'});
  </code></pre>
  
  <p>Strangely enough, this works when done from the shell:  </p>
  
  <pre><code>mongo mydatabase -u user -p password
  </code></pre>
  
  <p>so clearly, the credentials are right, and it's lining them up to the correct database, but something about the connection with Mongoose is not working...  </p>
  
  <p>Here is the shell command I passed in when creating that user:  </p>
  
  <pre><code>db.createUser({ 
    user: "user",
    pwd: "password",
    roles: [
      { role: "readWrite", db: "mydatabase" }
    ]
  });
  </code></pre>
  
  <p>I got a success message with this, and I confirmed by calling the <code>show users</code> command when using the <code>mydatabase</code> set  </p>
  
  <p>I'm at a real loss here.... Here's some of the prior research I have done that hasn't yet given me success:  </p>
  
  <blockquote>
    <p><a href="https://stackoverflow.com/questions/18216712/cannot-authenticate-into-mongo-auth-fails">Cannot authenticate into mongo, &quot;auth fails&quot;</a>  </p>
  </blockquote>
  
  <p>This answer suggests that it wouldn't be working because authentication happens at a database level, so I'm missing some sort of config option for my mongo instance, however the docs now say that such level authentication is disabled by default, and the docs the answer links to are since deprecated.</p>
  
  <blockquote>
    <p><a href="https://stackoverflow.com/questions/19391863/mongodb-mongoose-accessing-one-database-while-authenticating-against-another">MongoDB &amp; Mongoose accessing one database while authenticating against another (NodeJS, Mongoose)</a></p>
  </blockquote>
  
  <p>uses older version of Mongo that still have <code>addUser</code>
  On top of that, I don't see why that would work given it suggests I add a parameter to the 'auth' options that isn't listed in the documentation:<br>
  <a href="http://mongodb.github.io/node-mongodb-native/api-generated/db.html#authenticate" rel="nofollow noreferrer">http://mongodb.github.io/node-mongodb-native/api-generated/db.html#authenticate</a></p>
  
  <blockquote>
    <p><a href="http://mongoosejs.com/docs/connections.html" rel="nofollow noreferrer">http://mongoosejs.com/docs/connections.html</a></p>
  </blockquote>
  
  <p>Basically what I'm trying now, but isn't working.</p>
  
  <blockquote>
    <p><a href="https://stackoverflow.com/questions/12546657/authenticate-user-with-mongoose-express-js">authenticate user with mongoose + express.js</a>  </p>
  </blockquote>
  
  <p>I've tried a number of answers that involved doing something of this sort, that gave me the same error. Also, I'd rather avoid these type of solutions that require +80 lines of code to authenticate for now. I just want to get basic authentication down first.</p>