Heroku + mongoose connection error: no primary server found in set Heroku + mongoose connection error: no primary server found in set heroku heroku

Heroku + mongoose connection error: no primary server found in set


This may be a URI problem. The format for DB URIs is:

mongodb://<user>:<pass>@host:port,host:port,...,host:port/db_name

That means that

mongodb://username:password@someid-a0.mongolab.com:39897/pm_prod,mongodb://someid-a1.mongolab.com:39897

should be:

mongodb://username:password@someid-a0.mongolab.com:39897,someid-a1.mongolab.com:39897/pm_prod

It's also worth noting for others: If you are using Heroku's MongoLab add-on, your URI is available as an environment variable at process.env.MONGOLAB_URI, so you don't have to place the URI in your code.

This could also be related to a running question about connectivity between Heroku and Mongo. See https://github.com/jcottr/temps-mort, which references two tickets for the Node Mongo driver:

https://jira.mongodb.org/browse/NODE-4

https://jira.mongodb.org/browse/NODE-5