在springboot使用MongoDB时出现的bug和解决
在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:123456@127.0.0.1:27017/demo?authSource=admin&authMechanism=SCRAM-SHA-1
root是账号,123456是密码,demo是数据库名字,改为自己的
文章讲述了在SpringBoot项目中整合MongoDB时遇到的权限错误,提示MongoCredential问题。解决方法是修改mongodb.uri,包括用户名、密码、数据库名和认证源。

被折叠的 条评论
为什么被折叠?



