3

I'm trying to enable auth into my mongo server. I've already done:

-Configured security into mongo.conf

-Created the users(if use it with mongo -u -p..... from console works fine)

In the node server js my config is this

mongoose.connect(mongodb://user:pass@localhost:27017/dbName); 

Also I've already tried with

mongoose.connect(mongodb://user:pass@localhost:27017/dbName,{auth:{authdb:"admin"}}); 

And this

mongoose.connect(mongodb://user:pass@localhost:27017/dbName,{auth:{authdb:"dbName"}}); 

And always get this error:

Authentication failed 

What would be doing wrong?

2
  • i am not sure but try mongoose.connect ('mongodb://user:pass@localhost:27017/dbName',{auth:{authdb:"admin"}}) Commented May 8, 2017 at 12:04
  • Hi, I've already tried this and still not working Commented May 9, 2017 at 7:34

1 Answer 1

6

Try specifying the authDB like this -

mongoose.connect("mongodb://user:pass@localhost:27017/dbName?authSource=admin"); 
Sign up to request clarification or add additional context in comments.

1 Comment

Can you post how you connect using the terminal successfully?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.