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 . .