Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

221
Visualizações
How to configure mongoDB connection in heroku-deployed app?

An application deployed to heroku which connects to mongoDB will have issues in this connection attempt because IP's that connect to mongoDB have to be whitelisted inside mongo.

MongoDB docs here say:

To grant programmatic access to an organization or project using only the API, create an API key.

API keys have two parts: a Public Key and a Private Key. You can't use an API key to log into Atlas through the user interface.

All API keys belong to the organization, but can be given access to a project.

To create and manage API keys, use the Access Manager.

When you create a new API key, Atlas grants key the following permissions:

This is how i connected in development:

keys.js:

module.exports = {
  mongoURI: `mongodb+srv://user:password@cluster0.xl.mongodb.net/administrators?retryWrites=true&w=majority`,
  jwtSecret: 'secret'
}

server.js:

const db = require("./config/keys").mongoURI

mongoose
  .connect(db, { useNewUrlParser: true, useUnifiedTopology: true })
  .then(() => console.log("MongoDB connected"))
  .catch(err => console.log(err))

What i still dont understand is how to connect to mongoDB from a heroku deployed node.js app once you have an api key initialized??

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Since heroku dyno always has a random IP from a set of ranges there can be 3 possible ways:

  1. Using Heroku published IP ranges published in order to allow access to Heroku Dynos. This is highly not recommended since Heroku may change those ranges which can change.

  2. Use add-ons to provide outbound static IP to your application that you can add in Atlas network access.

  3. Buy Heroku private spaces which is somewhat expansive

Also if you can't afford to go for both of those recommended options you can allow access from anywhere which is also not highly recommended if you are building an application for production.

Hope it would help

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda