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,说明这个副本集还没初始化。

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

原文地址:https://www.cnblogs.com/flipped/p/12971539.html