开发者社区> 问答> 正文

node连接mongodb报错no primary found in replicaset如何解决?

启动gitlab上的fleximanage项目的时候启动失败,报错信息如下:

(node:676369) UnhandledPromiseRejectionWarning: MongoError: no primary found in replicaset or invalid replica set name
    at /root/src/flexiwan/fleximanage/backend/node_modules/mongo-express/node_modules/mongodb/lib/core/topologies/replset.js:624:11
    at done (/root/src/flexiwan/fleximanage/backend/node_modules/mongo-express/node_modules/mongodb/lib/core/topologies/replset.js:290:7)
    at Server.<anonymous> (/root/src/flexiwan/fleximanage/backend/node_modules/mongo-express/node_modules/mongodb/lib/core/topologies/replset.js:340:7)
    at Object.onceWrapper (events.js:422:26)
    at Server.emit (events.js:315:20)
    at Pool.<anonymous> (/root/src/flexiwan/fleximanage/backend/node_modules/mongo-express/node_modules/mongodb/lib/core/topologies/server.js:384:12)
    at Pool.emit (events.js:315:20)

环境信息如下:

  1. 系统环境:ubuntu 20.04
  2. mongodb版本:MongoDB server version: 4.0.9
  3. mongodb集群信息:

    
    {
        "_id" : "rs0",
        "version" : 1,
        "protocolVersion" : NumberLong(1),
        "writeConcernMajorityJournalDefault" : true,
        "members" : [
                {
                        "_id" : 0,
                        "host" : "172.26.218.169:27017",
                        "arbiterOnly" : false,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 1,
                        "tags" : {
    
                        },
                        "slaveDelay" : NumberLong(0),
                        "votes" : 1
                },
                {
                        "_id" : 1,
                        "host" : "172.26.218.169:27018",
                        "arbiterOnly" : false,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 1,
                        "tags" : {
    
                        },
                        "slaveDelay" : NumberLong(0),
                        "votes" : 1
                },
                {
                        "_id" : 2,
                        "host" : "172.26.218.169:27019",
                        "arbiterOnly" : true,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 0,
                        "tags" : {
    
                        },
                        "slaveDelay" : NumberLong(0),
                        "votes" : 1
                }
        ],
        "settings" : {
                "chainingAllowed" : true,
                "heartbeatIntervalMillis" : 2000,
                "heartbeatTimeoutSecs" : 10,
                "electionTimeoutMillis" : 10000,
                "catchUpTimeoutMillis" : -1,
                "catchUpTakeoverDelayMillis" : 30000,
                "getLastErrorModes" : {
    
                },
                "getLastErrorDefaults" : {
                        "w" : 1,
                        "wtimeout" : 0
                },
                "replicaSetId" : ObjectId("617f98c76948c437519a94d7")
        }
    

}



4. mongodb连接串`mongodb://root:root@172.26.218.169:27017,172.26.218.169:27018,172.26.218.169:27019/flexiwan?replicaSet=rs0&authSource=admin`


5. mongodb连接设置` {
    useNewUrlParser: true,
    useCreateIndex: true
  }`

请问有没有大神有思路帮忙看一下?多谢!

展开
收起
1020371570733451 2021-11-01 16:06:52 1921 0
1 条回答
写回答
取消 提交回答
  • 同样的问题,楼主解决了吗?

    2022-03-25 14:28:39
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
探究 Node.js 的服务端之路 立即下载
个推微服务实践 基于OpenResty 和Node.js 立即下载
沪江基于Node.js大规模应用实践 立即下载