Mongo::Error::NoServerAvailable: No primary server is available in cluster

I am getting the following error when deploying to production environment (via gitlab):

Mongo::Error::NoServerAvailable: No primary server is available in cluster:
#<Cluster topology= ReplicaSetNoPrimary[url1:27017,url2:27017,url3:27017,url4:27017,url5:27017,name=mobile01] servers=[ #<Server address=url1:27017 UNKNOWN>, #<Server address=url2:27017 UNKNOWN>, #<Server address=url3:27017 UNKNOWN>, #<Server address=url4:27017 UNKNOWN>, #<Server address=url5:27017 UNKNOWN>]> with timeout=30, LT=0.015

I have been trying to reproduce the error locally in a rails console, here is the configuration I have:

ap Mongoid.client(:default).instance_values
{ "srv_records" => nil, "options" => { "database" => "mydb", "auth_source" => "admin", "retry_reads" => true, "retry_writes" => true, "user" => "rp_projects", "password" => "xxxxxxxxxxxxxxxxx", "ssl" => true, "replica_set" => "mobile01", "connect" => :replica_set, "platform" => "mongoid-7.0.5" }, "database" => #<Mongo::Database:0x70156564542240 name=mydb>, "cluster" => #<Mongo::Cluster:0x70156564540720 servers=[] topology= ReplicaSetNoPrimary[url1:27017,url2:27017,url3:27017,url4:27017,url5:27017, name=mobile01]>
}

The server is running in a docker image. Am I missing something in the configuration? What should I look for here?

1 Answer

  1. Verify you are able to connect to the nodes using the MongoDB shell (mongo binary). Most likely you do not have connectivity.

  2. Set log level to debug () which will tell you what the driver is doing as it is attempting to connect to the deployment.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like