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

278
Visualizações
invalid schema, expected mongodb for process.env variable

I'm trying to set up mongodb for heroku and I can successfully connect if i put the url in the script normally. However, when I retrieve the url from environmental variables locally to hide it, I get the error 'invalid schema, expected mongodb'.

It's returning the exact same url in the format var url = 'mongodb://username:password@ds139619.mlab.com:39619/food'

Process.env isn't asynchronous is it? I can print the url correctly before the connect fails. I also checked the type and it is a string too.

//var url = 'mongodb://<username>:<password>@ds139619.mlab.com:39619/food';
var url = process.env.MONGOLAB_URI;
var ok = process.env.MONGOLAB_URI;

console.log(ok);


// Use connect method to connect to the Server
MongoClient.connect(url, function (err, db) {
if (err) {
    console.log('Unable to connect to the mongoDB server. Error:', err);
} else {
    console.log('Connection established to', url);

    // do some work here with the database.

    //Close connection
    db.close();
}
});
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I solved the problem by removing the quotations marks I used when saving the environment variables

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