Error information:
Caused by: com.mongodb.MongoCommandException: Command failed with error 18: ‘Authentication failed.’ on server XXXXXXX:27017. The full response is { “ok” : 0.0, “errmsg” : “Authentication failed.”, “code” : 18, “codeName” : “AuthenticationFailed” }
After consulting the data, it is found that the wrong authorized account number has been used
Each database in mongodb is independent of each other and has independent permissions. The correct way is to use the root account to create a sub account in the database to be operated, and then use this sub account to connect Mongo
>use admin
switched to db admin
>db.auth("root","123456")
1
>show dbs
admin 0.000GB
config 0.000GB
good 0.000GB
local 0.000GB
test 0.000GB
>use good
switched to db good
> db.createUser({user:"daniel",pwd:"123456",roles:[{role:"dbOwner",db:"good"}]})
Successfully added user: {
"user" : "daniel",
"roles" : [
{
"role" : "dbOwner",
"db" : "good"
}
]
}
Finally, in the Java code into the account, password and so on.
Similar Posts:
- mongodb not authorized on admin to execute command [version 3.2.18]
- Mongovue is unable to create collections and log in with user name and password
- Mongodb access control is not enabled for the database
- mongodb:E QUERY [thread1] SyntaxError: missing ; before statement @(shell):1:4
- How to Solve MongoDB Error: Authentication failed.
- [Solved] pymongo.errors.OperationFailure: Authentication failed.
- There is no PasswordEncoder mapped for the id “null” [How to Solve]
- Solution to the error of MySQL: unrecognized service (CentOS)
- When deploying Tomcat service, resolve the cannot invoke Tomcat manager exception
- When Navicat connects to a database on a server, there is an error prompt: 1130 ‘* *’ host is not allowed to connect to this MySQL server