在SpringBoot使用MongoDB时出现的bug和解决

在springboot使用MongoDB时出现的bug和解决

  • 在springboot整合MongoDB时,报错

在springboot整合MongoDB时,报错

INFO 67135 — [ main] org.mongodb.driver.connection : Closed connection [connectionId{localValue:2}] to 127.0.0.1:27017 because there was a socket exception raised by this connection.
org.springframework.data.mongodb.UncategorizedMongoDbException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName=‘root’, source=‘demo’, password=, mechanismProperties=}; nested exception is com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName=‘root’, source=‘demo’, password=, mechanismProperties=}

报错的话说是权限什么的,可以把properties文件中mongodb.uri改一下:

spring.data.mongodb.uri=mongodb://root:[email protected]:27017/demo?authSource=admin&authMechanism=SCRAM-SHA-1

root是账号,123456是密码,demo是数据库名字,改为自己的

你可能感兴趣的:(Bug专栏,spring,boot,mongodb,bug)