MongoDB is a popular open source document database that provides powerful features and flexible data storage. However, when connecting to MongoDB, you sometimes encounter "Authentication Failed" errors, which may be due to authentication failures. This article will introduce in detail how to troubleshoot MongoDB connection failures, and provide steps and detailed instructions to resolve "Authentication Failed" errors.
abnormal problem
To execute the command to switch the current database to "admin", use the following command:
>use admin
switched to db admin
When we authenticate using db.auth("admin", "admin"), we get "Error: Authentication failed" error. It is for this reason that it is impossible to connect to MongoDB through RoboMongo.
Steps
Here are the steps to take to resolve the "Authentication Failed" error:
Step 1: In order to manually add the "root" account, after the creation is successful, you can use the db.auth("root", "123456") command for identity verification. After the verification is successful, { ok: 1 } will be returned.
db.createUser(
{
user: "root",
pwd: "123456",
ro