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.