1 / 1
Nov 2024

Hello everyone, hope you are doing fine. This is my firs experience with mongodb so every suggestion is really appreciated.
I installed mongodb on almalinux9.
Then I connected with mongo command.
Then I did:

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

Then I attempted

mongo –host localhost -u admin -p ThisIsATest –authenticationDatabase admin

and got

Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused : connect@src/mongo/shell/mongo.js:380:17 @(connect):2:6 exception: connect failed exiting with code 1

then I did

cat /var/log/mongo/mongod.log | grep error

and I can see this error:

{"t":{"$date":"2024-11-15T10:47:13.670+01:00"},"s":"I", "c":"ACCESS", "id":20249, "ctx":"conn2","msg":"Authentication failed","attr":{"mechanism":"SCRAM-SHA-1","speculative":false,"principalName":"admin","authenticationDatabase":"–host","remote":"127.0.0.1:38088","extraInfo":{},"error":"UserNotFound: Could not find user \"admin\" for db \"–host\""}}

So as I said it’s my first time with mongodb and I don’t understand what in my connection string was wrong, UserNotFound seems strange to me.