Answer a question

I have a node.js app connected to a Mongo DB database,

I'm using the mongo URI link to connect from my web app.

I'm using DigitalOcean and I deployed the app to Heroku in order to check if I manage to avoid the:

failed to handshake with Mongo Error

for some reason, everything works great locally but when I deploy to production, I get this error accessing the production URL:

MONGODB Failed to handshake with db-shard-00-02-xyz.mongodb.net:27017: Mongo::Error::SocketError: EOFError: end of file reached (db-shard-00-02-xyz.mongodb.net:27017, TLS)

My Heroku config file:

production:
  clients:
    default:
      uri: <%= ENV['MONGODB_URI'] %>
      options:
        connect_timeout: 20

Thanks in advance.

Answers

You may want to check if your production IP is whitelisted in order to be able to connect to your Mongo DB.

You can edit your mongo configuration on:

cloud.mongodb.com > Network Access > IP Whitelist

You can test if this is the issue by opening it to all:

0.0.0.0/0

hope it helps!

Logo

MongoDB社区为您提供最前沿的新闻资讯和知识内容

更多推荐