MongoServerError: Authentication failed on Ubuntu
P粉627427202
P粉627427202 2023-09-13 18:04:33
0
1
548

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

P粉627427202
P粉627427202

reply all(1)
P粉035600555
  1. Please use the correct username
  1. Please check the mongo version, I think the root role does not include any access to collections in versions prior to 3.07. If it is a previous version, you can use the following command.
use admin
    db.addUser( { user: "<username>",
              pwd: "<password>",
              roles: [ "userAdminAnyDatabase",
                       "dbAdminAnyDatabase",
                       "readWriteAnyDatabase"
    ] } )
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template