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

273
Visualizações
Unable to connect to my database from my node js application

I've been trying to connect my application to my database, but it has not been possible. I've tried this below, and it still did not recognize my models

const MongoClient = require('mongodb').MongoClient;
const assert = require('assert');

// Connection URL
const url = process.env.MONGODB_URL;

// Database Name
const dbName = 'KaydeeAcedemy';

// Use connect method to connect to the server
MongoClient.connect(url, { useNewUrlParser: true, useUnifiedTopology: true }, function(err, client) {
    assert.equal(null, err);
    console.log("Connected successfully to server");

    const db = client.db(dbName);

    client.close();
});

I've also tried using this connection string, yet no headway.

const { MongoClient } = require('mongodb');
const uri = process.env.MONGODB_URL;
const client = new MongoClient(uri, { useNewUrlParser: true, useUnifiedTopology: true });
client.connect(err => {
    const collection = client.db("test").collection("devices");
    // perform actions on the collection object
    client.close();
  });

when I try to add a new user from my application, i get this error as a result of the database.

Operation `users.findOne()` buffering timed out after 10000ms

the mongodb url looks like this:

MONGODB_URL = mongodb+srv://Kaydeeacademy:**************@cluster0.ehclf.mongodb.net/KaydeeAcademy?retryWrites=true&w=majority

I don't know if I missed something in the connection string or somewhere.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Can you test/compare out some of my code (working)

// have you called in the dot.env file?
require('dotenv').config()
const express = require('express')
const mongoose = require('mongoose')


// don't include the "useNewUrlParser: true, useUnifiedTopology: true" see answer below:
// https://stackoverflow.com/questions/68915722/option-usefindandmodify-is-not-supported


// make sure there are no spaces in the dot.env file
mongoose.connect(process.env.MONGO_URI)
  .then(() => console.log("db connected!"))
  .catch(err => console.error("db connection failed ", err))
about 4 years ago · Juan Pablo Isaza 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