美文网首页
springboot 连接mongo副本集报错记录

springboot 连接mongo副本集报错记录

作者: LX_代码制造坊 | 来源:发表于2021-01-18 12:19 被阅读0次
    连接失败问题

    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
    

    相关文章

      网友评论

          本文标题:springboot 连接mongo副本集报错记录

          本文链接:https://www.haomeiwen.com/subject/sesqzktx.html