This typically happens when MongoDB is unable to locate the user you have created in the admin database. This can occur if the user was not created successfully or the authentication process was misconfigured.
To resolve this:
Ensure you are using the correct MongoDB version and follow the official installation steps for your OS.
After installation, try connecting without authentication first by running the mongo shell and then create the admin user by running:
use admin;
db.createUser({
user: "admin",
pwd: "yourPassword",
roles: [{ role: "root", db: "admin" }]
});
After creating the user, restart the MongoDB service and then attempt connecting again using the correct username and password with the --authenticationDatabase admin option.