Article posted on : link to source

Having trouble connecting to MongoDB replica sets after upgrading the MongoDB Ruby driver to 2.5.x? We’ve recently received a few inquiries about this issue with the latest MongoDB Ruby driver version and wrote this post to share our findings on the problem and cause.

The error message that was encountered on connection attempt was –

No server is available matching preference: #<Mongo::ServerSelector::Primary:…>

The issue had been already reported to MongoDB and is being tracked here. We spent some time to investigate this issue and the root cause introduced in the driver code in 2.5.x.

MongoDB Ruby Driver 2.5.x Issue Summary

The issue exists in the 2.5.x version(s) of the MongoDB Ruby driver and is encountered when the hostnames comprising of the replica set contain case-sensitive characters, for example, Possible workarounds are:

 Downgrade to 2.4.x or upgrade 2.6.x once it’s made available.
Change the hostnames of all the members of the replica sets to downcase. For example, change the hostname in the example above to

Details On The Issue

Enabling detailed logging on Ruby provided a clue on what was happening:

#19140] DEBUG — : MONGODB | Topology type ‘replica set’ initializing.
#19140] DEBUG — : MONGODB | Server initializing.
#19140] DEBUG — : MONGODB | Server description for changed from ‘unknown’ to ‘unknown’.
#19140] DEBUG — : MONGODB …

Read More on Datafloq

%d bloggers like this: