springboot 连接mongo副本集报错记录

2021-01-18  本文已影响0人  LX_代码制造坊
连接失败问题

Please use 'MongoMappingContext#setAutoIndexCreation(boolean)' or override 'MongoConfigurationSupport#autoIndexCreation()' to be explicit.
However, we recommend setting up indices manually in an application ready block. You may use index derivation there as well.

解决方法,在配置文件中添加配置:

spring:
  #数据源配置
  data:
    mongodb:
      uri: mongodb://127.0.0.1:27017/test
      auto-index-creation: false
启动报错问题

com.mongodb.MongoNotPrimaryException: Command failed with error 10107 (NotMaster): 'not master' on server 127.0.0.1:27017
解决方法,需要将配置中的url改为:

uri: mongodb://172.17.0.4:27017,172.17.0.5:27017,172.17.0.6:27017/test?connect=replicaSet&slaveOk=true&replicaSet=rs
上一篇下一篇

猜你喜欢

热点阅读