I installed Mongodb on Ubuntu 22.04. I use this line of code to setup admin on Mongodb
test\> use admin
Switch to database administrator
admin\> db.createUser({user:"john", pwd:"alx", roles:\[{role:"root", db:"admin"}\]}) { ok: 1 }
Enable MongoDB authentication in/lib/systemd/system/mongod.service
by adding this line of code
ExecStart=/usr/bin/mongod --quiet --auth --config /etc/mongod.conf
Then I run this command
mongosh -u demo -p --authenticationDatabase admin
This error occurs after entering alx as password
enter password:
Current Mongosh log ID: 64af5b02457d8abc538e7e4f
Connect to: mongodb://
@127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&authSource=admin&appName=mongosh 1.10.1 MongoServerError: Authentication failed
I try to log in to the Mongodb database via authentication