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