问题:

连接数据库时报错

com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName=‘root’, source=‘gateway’, password=, mechanismProperties=} Command failed with error 18 (AuthenticationFailed): ‘Authentication failed.’ on server 192.168.81.13:27017. The full response is {“ok”: 0.0, “errmsg”: “Authentication failed.”, “code”: 18, “codeName”: “AuthenticationFailed”}.

解决

连接uri

mongodb://user:password@host:port/dbname

增加参数 authSource

例如:

mongodb://user:password@host:port/dbname?authSource=admin

一般情况下authSource是admin,根据需要替换

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐