2 / 3
Nov 2024

I am a bit confused here.
I Installed mongodb on almalinux9.
Then I connected with
mongo
and did

use admin; db.createUser( { user: "admin", pwd: "ThisIsATest", roles: [ { role: "root", db: "admin" } ] } ); exit

now from the same shell i am attempting
mongo –host localhost -u admin -p ThisIsATest –authenticationDatabase admin
but I get an error:

connecting to: mongodb://127.0.0.1:27017/%E2%80%93host?compressors=disabled&gssapiServiceName=mongodb Error: Authentication failed. : connect@src/mongo/shell/mongo.js:380:17 @(connect):2:6 exception: connect failed exiting with code 1

if I check the logs:

cat /var/log/mongo/mongod.log | grep error ` it shows:`` "id":20249, "ctx":"conn3","msg":"Authentication failed","attr":{"mechanism":"SCRAM-SHA-1","speculative":false,"principalName":"admin","authenticationDatabase":"–host","remote":"127.0.0.1:54028","extraInfo":{},"error":"UserNotFound: Could not find user \"admin\" for db \"–host\""}}

I am definitely doing something wrong but need to find out what.

What shows as -host is actually not a double dash -- as it should be, this has been parsed as a database to connect to(and authenticate on). This is visible in the connecting to message %E2%80%93host

An autocorrect or some other helpful thing has likely updated the original and copy/paste to the terminal, this is the result.

Try typing this out in full instead.

mongo has been end of life since MongoDB 6.0 and replaced with mongosh

2 months later

Closed on Jan 16

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.