最近新起一项目用到了mongodb,然后直接采用 spring-boot-starter-data-mongodb 做依赖直接使用框架的mongodb配置,连接mongo然后开发及测试都没问题,上生产环境后项目也启动正常(项目启动时也能正常连接mongodb)老手新发咔咔的就上线了,本来信心满满,上线后直接就交给用户用了,然后被啪啪打脸了,原因是当点击导出数据从mongo往外导数据的时候报异常,异常如下(很常见的异常吧,但启动能正常连接,查询数据也应该没问题才对):

Command failed with error 18 (AuthenticationFailed): 'Authentication failed.' on server dds-***************-pub.mongodb.rds.aliyuncs.com:3717. The full response is {"operationTime": {"$timestamp": {"t": 1650956849, "i": 15}}, "ok": 0.0, "errmsg": "Authentication failed.", "code": 18, "codeName": "AuthenticationFailed", "$clusterTime": {"clusterTime": {"$timestamp": {"t": 1650956849, "i": 15}}, "signature": {"hash": {"$binary": {"base64": "bVMy9hNiEO6bzj2IcPay57ku460=", "subType": "00"}}, "keyId": 7042646381365821444}}}

这一看就是启用认证错误嘛,但是看异常信息,明明已经正常读取到配置的用户信息了,而且同样的配置信息在另外一个项目上就可以正常使用,在尝试对用户名密码加双引号等解决方案无效后,就用起了杀手锏“自定义配置”直接自己写mongodb的配置信息(不再采用默认的配置项),经过将老项目的配置信息copy并修改后配置信息如下:

    /*** mongoDb配置项** @return* @author wjyuse@foxmail.com* @date 2022-04-26 15:46:50**/@Beanpublic MongoDatabaseFactory mongoDbFactory() throws Exception {// Set credentialsMongoCredential credential = MongoCredential.createCredential(userName, database, password.toCharArray());ServerAddress serverAddress = new ServerAddress(host, port);// Mongo ClientMongoDriverInformation info = MongoDriverInformation.builder().build();MongoClientSettings build = MongoClientSettings.builder().applyToClusterSettings(builder -> builder.hosts(Collections.singletonList(serverAddress))).credential(credential).build();MongoClient mongoClient = new MongoClientImpl(build, info);// Mongo DB Factoryreturn new SimpleMongoClientDatabaseFactory(mongoClient, database);}

再次放入生产环境后终于OK了。

PS:有时候隐藏在深不见底的地方,哪怕再老的老手也尽量不轻易拍胸脯,否则,有可能会听到啪啪啪的声音!

MongoDb连接认证错误(Command failed with error 18)相关推荐

  1. Command failed with error 10107: ‘not master‘ on server 10.2.2.139:27017. Closed connection

    springboot 连接mogodb,报错Command failed with error 10107: 'not master' on server Closed connection [con ...

  2. spring.data.mongodb.uri认证失败Authentication failed

    使用spring.data.mongodb.uri=mongodb://root:ve#duj7-wa06yhg$@192.154.81.16:27017/xxxx老是出现Authentication ...

  3. mongodb连接认证失败

      版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/qq_29143909/articl ...

  4. 账号密码连接远程阿里云mongodb服务,报错 AuthenticationFailed,code:18

    root 账号访问 阿里云mongodb服务 的 admin数据库 可以, 但是访问其他数据库报错 AuthenticationFailed: ERROR StatusLogger The datab ...

  5. 阿里云ECS lnmp linux7 安装mongodb连接不上 child process failed, exited with error number

    linux安装mongodb安装网上有很多教程,我就不赘述了: ##安装mongodb连接:https://www.cnblogs.com/Lovebugs/p/8606000.html 我主要总结一 ...

  6. Python3安装turtle提示错误:Command python setup.py egg_info failed with error code 1

    Python3安装turtle提示错误:Command "python setup.py egg_info" failed with error code 1 Python3.5安 ...

  7. clang++.exe: error: linker command failed with exit code 1 错误解决方法

    clang++.exe: error: linker command failed with exit code 1 错误解决方法 错误信息如下: Build command failed. Erro ...

  8. 解决 win10 pycurl安装出错 Command python setup.py egg_info failed with error code 10 编译安装包 安装万金油...

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/yexiaohhjk/article/d ...

  9. iOS引入第三发库引发的错误linker command failed with exit code 1

    引入第三发库导致项目崩溃 常见出错日志: Apple Mach-O Linker Error Group linker command failed with exit code 1 (use -v ...

最新文章

  1. 使用rsync实现数据实时同步备份--实战
  2. C语言写的俄罗斯方块
  3. java 实体属性个数_?Java中比较实用实体转换工具介绍
  4. Java线程--BlockingQueue使用
  5. 【Machine Learning】TensorFlow实现K近邻算法预测房屋价格
  6. Python 自带性能强悍的标准库 itertools
  7. electron打包失败在下载nsis的地方
  8. 谷歌flutter_在Flutter中使用Google Pay Through Stripe接受付款
  9. survival | 生存分析(3):生存曲线(下)
  10. 互联网+双“高新”时代
  11. 异常收集 ----雨之殇
  12. 精诚探索,极客归来!百度安全打造全球首个元宇宙安全极客大会,共筑 AI 安全新防线...
  13. 计算机辅助电路小结,电子电路计算机辅助设计实训报告.doc
  14. 全球及中国M2M组件行业发展动态及未来发展趋势预测报告2022~2027年
  15. IPv6 地址数量有多少,能够分配到地球上的每一粒尘埃吗
  16. Note | LaTeX
  17. Web送货单打印管理系统毕业设计
  18. Opencv之利用matchshape算子实现简单的形状匹配
  19. 数据三维可视化的全介绍
  20. 墨墨背单词刷分享链接访问量(动态获取IP代理池)

热门文章

  1. 一种基于微博的喂狗装置实现设想
  2. 机器学习中分类算法的优缺点
  3. 2022年1月13日学习总结
  4. Vue3+ElementPlus设置菜单选中
  5. 润迈德医疗通过上市聆讯:预计亏损将增加,霍云飞兄弟持股约33%
  6. 【亲测】群晖Docker安装qb(qbittorrent)实现替代自带软件(速度肯定是好很多)
  7. SAP PS模块的预算管理
  8. chimee hls m3u8
  9. CCTV4:中国智造亮出新名片,深兰科技熊猫公交驰骋粤港澳大湾区!
  10. Go语言中 defer 的用法