server selection timeout, current topology: { Type: ReplicaSetNoPrimary, Servers: Type: RSGhost 错误的解决方法

编写容器内运行的集成测试,需要用到 MongoDB 的 replica set,在程序连接数据库时报了这样的错:

server selection timeout, current topology: { Type: ReplicaSetNoPrimary, Servers: Type: RSGhost ...

原因是要连接的 ReplicaSet 找不到 Primary,只有一个 RSGhost,说明这个副本集还没初始化。

检查初始化脚本的输出日志,发现是有个脚本没挂载。

posted @ 2020-05-27 11:30  水郁  阅读(3196)  评论(0编辑  收藏  举报
……