Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

275
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda