我在数据库的admin中创建了一个管理员,角色是root,其他普通数据库都没创建,可用mongoose连接普通数据库example怎么都连接不上,说not authorized on example to execute command ,加上admin的用户名和密码也无法登陆,报错为Authentication failed。求大佬告知怎么改。
1. The admin username and password cannot log in, and the error is Authentication failed.
When logging in as an administrator (your configured role is root), please configure authenticationDatabase "admin"; for example, in the mongo command line:
2. You can use mongoose to connect to the ordinary database example but cannot connect, saying not authorized on example to execute command
The correct step is to use the administrator to create the database user required for the application, assign permissions, and then log in. For example:
Create user/assign permissions, specify user name, permissions, and corresponding database, for example, on the command line: db.createUser( {
1. The admin username and password cannot log in, and the error is Authentication failed.
When logging in as an administrator (your configured role is root), please configure authenticationDatabase "admin"; for example, in the mongo command line:
mongo -u "root" -p "root" --authenticationDatabase "admin"
2. You can use mongoose to connect to the ordinary database example but cannot connect, saying not authorized on example to execute command
The correct step is to use the administrator to create the database user required for the application, assign permissions, and then log in. For example:
Create user/assign permissions, specify user name, permissions, and corresponding database, for example, on the command line:
db.createUser(
{
}
)
When logging in, connect to the example database, for example, from the command line:
mongo -u "app" -p "app" --authenticationDatabase "example"
For reference.
Love MongoDB! Have Fun!
I just encountered this problem recently, you can take a look at this http://kdylan.me/2016/12/11/m...