nodejs连接mongodb时,使用集群方式报错

2017-09-22T01:42:32.115Z - error: db connect failed

2017-09-22T01:42:32.124Z - error:  MongoError: no primary found in replicaset

    at /opt/b2b/jiathis-service/node_modules/mongodb-core/lib/topologies/replset.js:560:28

    at null.<anonymous> (/opt/xxxx-service/node_modules/mongodb-core/lib/topologies/replset.js:312:24)

    at g (events.js:260:16)

    at emitOne (events.js:77:13)

    at emit (events.js:169:7)

    at /opt/b2b/jiathis-service/node_modules/mongodb-core/lib/topologies/server.js:300:14

    at /opt/b2b/jiathis-service/node_modules/mongodb-core/lib/connection/pool.js:469:18

    at nextTickCallbackWith0Args (node.js:420:9)

    at process._tickCallback (node.js:349:13)

解决方式

  一、使用非集群方式连接mongodb,去掉replicatSet参数

    db: 'mongodb://username:password@IP/db_name'

  OR

  二、在mongodb中,配置集群 ,去掉replSet前面的#号,并设置你的集群名字 /etc/mongod.conf

      

# in replicated mongo databases, specify the replica set name here
#replSet=setname

  添加实例到replica set

rs.initiate()

rs.add("IP:27017")
#查看配置
rs.conf()

最新文章

  1. 剑指Offer面试题:11.打印1到最大的n位数
  2. POJ1741:tree
  3. BZOJ3780 : 数字统计
  4. PIT,BL,AP,CP,CSC
  5. 第二百零九天 how can I 坚持
  6. system进程启动普通用户进程调研
  7. linode最新试用(购买)流程
  8. chapter 12_1 数据文件
  9. 关于win8/win8.1系统不能调节亮度的解决办法
  10. Linux查看系统版本号及关机命令各种方法归纳
  11. java对象在内存中的结构
  12. Java运行时数据区
  13. JS 实现版本号比较功能
  14. node之http模块总结
  15. 《无所不能的JavaScript编程系列:setTimeout 简笔》
  16. R-CNN阅读笔记
  17. 在终端上创建Java项目及编译和运行
  18. node.js学习笔记(三)——事件循环
  19. docker node项目 连接mongodb
  20. git推送到github报错:error: The requested URL returned error: 403 Forbidden while accessing https://github.com

热门文章

  1. [转]C++11常用特性的使用经验总结
  2. 3.4 unittest之装饰器(@classmethod)
  3. centos安装redis步骤
  4. lvm快照
  5. lvs UDP端口负载均衡配置
  6. Windows下将文件打包压缩成 .tar.gz格式
  7. linux nodejs
  8. E212: Can&#39;t open file for writing Press ENTER or type command to continue
  9. SpringMVC复习
  10. 纯CSS制作图形效果