node.js - Authentication always failing when connecting to MongoDB -


i using node/express node_modules = "mongodb": "2.0.33", "mongoose": "3.8.15",

mongo shell version: 3.0, , mongo 3.0

i'm able connect mongodb fine, if pass in authentication parameters, fail:

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

the following shows in logs when happens:
2015-06-13t15:10:09.863-0400 access [conn8] authenticate db: mydatabase { authenticate: 1, user: "user", nonce: "xxx", key: "xxx" } 2015-06-13t15:10:09.863-0400 access [conn8] failed authenticate user@mydatabase mechanism mongodb-cr: authenticationfailed usernotfound not find user user@mydatabase

i've done quite few patterns try work.

here's happens when show users command in mongo shell while on appropriate database:

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

here's attempt connect particular database while passing in correct parameters:

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

for measure tried passing in options hash instead of passing params via uri:

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

strangely enough, works when done shell:
mongo mydatabase -u user -p password
clearly, credentials right, , it's lining them correct database, connection mongoose not working...

here shell command passed in when creating user:

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

i got success message this, , confirmed calling 'show users' command when using 'mydatabase' set

i'm @ real loss here.... here's of prior research have done hasn't yet given me success:

cannot authenticate mongo, "auth fails"
^ answer suggests wouldn't working because authentication happens @ database level, i'm missing sort of config option mongo instance, docs such level authentication disabled default, , docs answer links since deprecated.

mongodb & mongoose accessing 1 database while authenticating against (nodejs, mongoose)
^ uses older version of mongo still have 'adduser'

on top of that, don't see why work given suggests add parameter 'auth' options isn't listed in documentation:
http://mongodb.github.io/node-mongodb-native/api-generated/db.html#authenticate

http://mongoosejs.com/docs/connections.html
^ i'm trying now, isn't working.

authenticate user mongoose + express.js
^ i've tried number of answers involved doing of sort, gave me same error. also, i'd rather avoid these type of solutions require +80 lines of code authenticate now. want basic authentication down first.

you mentioned using mongodb 3.0. in mongodb 3.0, supports multiple authentication mechanisms.

  1. mongodb challenge , response (scram-sha-1) - default in 3.0
  2. mongodb challenge , response (mongodb-cr) - previous default (< 3.0)

if started new 3.0 database new users created, have been created using scram-sha-1.

so need driver capable of authentication:

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

if had database upgraded 2.x existing user data, still using mongodb-cr, , user authentication database have upgraded:

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

specific particular environment mongoose compatibility version doesn't appear support 3.0 due mongodb node.js driver in use (see compatibility page on mongoose site--sorry, can't post more 2 links currently).

i suggest update mongoose.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -