When connecting to MongoDB authentication always fails

I use node / express node_modules = "mongodb": "2.0.33", "mongoose": "3.8.15",

mongo shell version: 3.0 and mongo 3.0

I can connect to my mongoDB just fine, but if I go through any authentication settings, it will fail:

```connection error: { [MongoError: auth failed] name: 'MongoError', ok: 0, errmsg: 'auth failed', code: 18 }
```  

Logs display the following:
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

I made some templates to try to get this to work.

This is what happens when I make the show users command in the mongo shell while in the corresponding database:

{ "_id" : "mydatabase.user", "user" : "user", "db" : "mydatabase", "roles" : [ { "role" : "readWrite", "db" : "mydatabase" } ] }

Here is my attempt to connect to this particular database while passing the correct parameters:

mongoose.connect('mongodb://user:password@host:port/mydatabase');

For a good measure, I also tried passing a hash of parameters instead of passing parameters via uri:

```mongoose.connect('mongodb://host:port/mydatabase',{user: 'user',pass: 'password'});```

, , :
mongo mydatabase -u user -p password
, , , - Mongoose ...

, :

```
db.createUser({ 
  user: "user",
  pwd: "password",
  roles: [
    { role: "readWrite", db: "mydatabase" }
  ]
});
```  

, , show show "mydatabase"

... , , :

," auth failed "
^ , , , - mongo, , , docs .

MongoDB Mongoose (NodeJS, Mongoose)
^ Mongo, addUser

, , , , "auth", :
http://mongodb.imtqy.com/node-mongodb-native/api-generated/db.html#authenticate

http://mongoosejs.com/docs/connections.html
^ , , .

mongoose + express.js
^ , - , . , , +80 . .

+4
2

, MongoDB 3.0. MongoDB 3.0 .

  • MongoDB (SCRAM-SHA-1) - 3.0
  • MongoDB Challenge Response (MONGODB-CR) - (< 3.0)

3.0 , SCRAM-SHA-1.

, :

http://docs.mongodb.org/manual/release-notes/3.0-scram/#considerations-scram-sha-1-drivers

2.x , MONGODB-CR, :

http://docs.mongodb.org/manual/release-notes/3.0-scram/#upgrade-mongodb-cr-to-scram

Mongoose 3.0 - MongoDB Node.js(. Mongoose - , ).

Mongoose.

+3

Mongo v3.0 +:

db ( ). , createUser afaict.

- 'use' creatUser.

, db , auth .

0

All Articles