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

300
Vistas
connection of deno to mongodb fails

I'm trying to connect my deno application to mongodb but I get error.

import {MongoClient} from "https://deno.land/x/mongo@v0.21.2/mod.ts";

const client = await new MongoClient();
await client.connect("mongodb+srv://deno:i4vY8AtCEhr6ReqB@sample.7jp1l.mongodb.net/deno?retryWrites=true&w=majority");

const db = client.database("notes");

export default db;

everything seem to be fine but when I run the app, I get this error.

error: Uncaught (in promise) Error: MongoError: "Connection failed: failed to lookup address information: nodename nor servname provided, or not known"
                throw new MongoError(`Connection failed: ${e.message || e}`);
              ^
    at MongoClient.connect (client.ts:93:15)
    at async mongodb.ts:4:1
over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

2 problems that I see:

  • The code snippet above only works with Mongo installed in local machine.
  • The connection string use DNS Seed List, but the current library couldn't resolve to a list of hosts

To make it works with Mongo Atlas, you need to call a connect method with difference parameters and find a correct (static) host instead a (dynamic) DNS Seed List:

const client = new MongoClient();

const db = await client.connect({
  db: '<your db or collection with work with>',
  tls: true,
  servers: [
    {
      host: '<correct host - the way to get the host - see bellow>',
      port: 27017,
    },
  ],
  credential: {
    username: '<your username>',
    password: '<your password>',
    mechanism: 'SCRAM-SHA-1',
  },
});

How to get the correct host:

  • Open your Cluster in Mongo Atlas
  • Select Connect button
  • Select Connect to application option
  • Select Driver: Node.js and Version: 2.2.12 or later
  • Here you will see a list of host follow @ character
over 4 years ago · Santiago Trujillo Denunciar

0

Thank you @nthung.vlvn for the clue. Indeed the host needs to be a primary shard. It fixed the lookup address information, but I had another error, that my credentials are incorrect. I had to add db "admin" to credential:

credential: {
    username: '<your username>',
    password: '<your password>',
    db: "admin",
    mechanism: 'SCRAM-SHA-1',
}

That is weird, because I do not have admin db in my Atlas. Anyway it started to work.

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