4

I have an application that connects to a MongoDB database called discussions. I've created a user

Mongo shell:

> use discussions
switched to db discussions
> db.auth("discussions","XXXXXXXXX")
1
> show users
{
        "_id" : "discussions.discussions",
        "user" : "discussions",
        "db" : "discussions",
        "roles" : [
                {
                        "role" : "dbOwner",
                        "db" : "discussions"
                }
        ]
}

So that is to confirm that I do have one account on the database and it's a dbOwner. According to the docs it has READ, WRITE, etc privileges.

The configuration file has the property "auth = true" enabled, and the service has been bounced since the change, more than once.

However, the problem is that when I attempt to connect to the database from outside of the shell I always get the error:

mongo  discussions -u 'discussions' -p 'XXXXXXXXX'
MongoDB shell version: 2.6.3
connecting to: discussion
2014-08-05T01:00:39.026+0400 Error: 18 { ok: 0.0, errmsg: "auth failed", code: 18 } at src/mongo/shell/db.js:1210
exception: login failed

I've seen questions on Stackoverflow about this and they all had something to do with the quotes used around the username and password... but changing the single quote to a double quote didn't yield a better result.

monksy
  • 357
  • 1
  • 3
  • 14

2 Answers2

5

Maybe I'm wrong but the correct form is like this:

mongo --port 27017 -u manager -p 12345678 --authenticationDatabase admin

You can read about this in mongo documentation:

http://docs.mongodb.org/manual/tutorial/add-user-to-database/

  • The default is 27017 for port. Also the authenticationDatabase has the discussions user to be valid on admin and the "discussions" database. – monksy Aug 04 '14 at 21:14
2

The issue was resolved by removing any symbols. It appears that despite quotes [single or double] would cause the incoming password to be invalid.

monksy
  • 357
  • 1
  • 3
  • 14
  • In my case, I tried to connect with mongoose and I wasted 2 hours because of my database name had an underscore – MudithaE Sep 26 '18 at 14:52