Java连接Mongo
String[] ips="10.1.1.191:27017".split(","); String database = "aoe_mongo"; String username = "admin"; String password = "123456";
Caused by: com.mongodb.MongoCommandException: Command failed with error 18 (AuthenticationFailed): 'Authentication failed.' on server 10.1.1.191:27017. The full response is {"ok": 0.0, "errmsg": "Authentication failed.", "code": 18, "codeName": "AuthenticationFailed"}
或用工具连接
排查原因:使用了错误的授权账号
MongoDB中每个数据库之间是相互独立的,都有独立的权限,正确的做法是使用root账号在【将要操作的数据库】中创建一个【user】,在用这个user连接mongo:
再次连接可以了。