Jasmine Lognnes Jasmine Lognnes - 2 years ago 318
Linux Question

Why UserNotFound error in MongoDB?

I would like to be able to access

mongodb://admin:[email protected]:27017/testdb
, but I keep getting

Command: ./node_modules/east/bin/east migrate --adapter east-mongo --url mongodb://admin:[email protected]/testdb
[conn7] SCRAM-SHA-1 authentication failed for admin on testdb from client ; UserNotFound Could not find user [email protected]

is the hostname. This is what I have done:

mongod --storageEngine wiredTiger --httpinterface --rest --master --auth &
mongo admin --eval "db.createUser({user: 'admin', pwd: 'password', roles:[{role:'root',db:'admin'}]});"

If I do

mongo admin -u admin -p password --host db --port 27017

show dbs

Now I want to access
which I haven't created yet, but from my understanding databases that doesn't exist are created on the fly?

mongo testdb -u admin -p password --host localhost --port 27017
2016-06-08T16:14:02.146+0200 E QUERY Error: 18 Authentication failed.


Can anyone see why I can't connect?

Answer Source

You are trying to authenticate against a database that is non-existent or empty. This is why the authentication fails.

I would

  1. log in into MongoDB.
  2. execute use testdb to switch to testdb database
  3. execute db.createuser(...) with the appropriate options to create a user/password which you can use to authenticate with

Then you should be able to do what you described.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download