Could not find host matching read preference - Force new election

Hi all,

I am posting this here in case this helps anyone else who may get stuck with this error when attempting to get through the Lab - Shard a Collection challenge. I see that there is another thread here in this forum that highlights the same error, but in my case the reason for the error is/was a bit different:

"errmsg" : "Could not find host matching read preference { mode: \"primary\" } for set m103-repl",

In my case, it turned out that somewhere along the way the primary in my initial replicaset m103-repl had stepped down and become a secondary. All that I needed to do was to connect the the new primary, then force a new election to reinstate my 1st node (ie., running on port 27001) as the primary again. Then I was able to run sh.addShard again without the error above.

Cheers:-)

1 Like

Hi @juliettet,

We really appreciate you sharing this with our community. If you ever get stuck anywhere, please feel free to get back to us.

Happy Learning :slight_smile:

Thanks,
Muskan
Curriculum Support Engineer