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

796
Vistas
Unable to connect with Mongodb database using Nodejs

I am trying to connect Mongodb database with Nodejs, but it's showing below error:

Error MongoServerSelectionError: connection <monitor> to 18.235.147.2:27017 closed
at Timeout._onTimeout (D:\Backend\NodeJs\PapersBackend\node_modules\mongodb\lib\core\sdam\topology.js:438:30)
at listOnTimeout (internal/timers.js:549:17)
at processTimers (internal/timers.js:492:7) {
reason: TopologyDescription {
type: 'ReplicaSetNoPrimary',
setName: null,
maxSetVersion: null,
maxElectionId: null,
servers: Map {
  'cluster0-shard-00-01.ef0q5.mongodb.net:27017' => [ServerDescription],
  'cluster0-shard-00-02.ef0q5.mongodb.net:27017' => [ServerDescription],
  'cluster0-shard-00-00.ef0q5.mongodb.net:27017' => [ServerDescription]
},
stale: false,
compatible: true,
compatibilityError: null,
logicalSessionTimeoutMinutes: null,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
commonWireVersion: null
}
}

I am unable to get what exactly issue is below is my code:

const express = require('express');
const router = express.Router();
const MongoClient = require('mongodb').MongoClient;

const dburl = 'mongodb+srv://digi18:<myPasssword>@cluster0.ef0q5.mongodb.net/MyDb? 
                 retryWrites=true&w=majority';

router.use(express.json());
router.use(express.urlencoded({ extended: true }));

router.post('/register',(req,res) => {

MongoClient.connect(dburl,{ useNewUrlParser:true,useUnifiedTopology: true },(err,client) => {
            
     if(err){
         console.log("Error",err);
         }
     else{
        res.send("Connect");
        }
    });  
 });

module.exports = router;

What am I doing wrong?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

I resolved this issue by simply making network access in Mongodb Atlas dashboard from access from anywhere to add current ip. I don't know whether it's an issue from Mongodb side or there is some other way out.

over 4 years ago · Santiago Trujillo 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