Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deno Uncaught Error: No such host is known. (os error 11001)

Tags:

mongodb

deno

I tried to connect the MongoDB Atlas to my Deno Application using https://deno.land/x/[email protected] framework. I tried the below code to run my application. but I get an error No such host is known. (os error 11001) What went wrong here

Error

error: Uncaught Error: No such host is known. (os error 11001)
    at unwrapResponse (rt\10_dispatch_json.js:24:13)
    at sendAsync (rt\10_dispatch_json.js:75:12)
    at async Object.connect (rt\30_net.js:221:13)
    at async MongoClient.connect (client.ts:41:14)
    at async mongodb.ts:33:1

Mongodb.ts File

import { MongoClient } from "https://deno.land/x/[email protected]/mod.ts";
    
    const client1 = new MongoClient();
    await client1.connect("mongodb+srv://user1:[email protected]/TestingDB?retryWrites=true&w=majority");
    
    const db = client1.database("TestingDB");
    
    export default db;

I used this command to run my server

deno run --allow-net --allow-write --allow-read  --allow-plugin --unstable server.ts
like image 359
Prasath Avatar asked Jan 21 '26 09:01

Prasath


1 Answers

I fixed this using https://www.youtube.com/watch?v=hhdhydffKKE this video reference

Follow these steps to fix this

    import { MongoClient } from "https://deno.land/x/[email protected]/mod.ts";
    
    const client1 = new MongoClient();
    
    await client.connect({
    db: "<db>",
    tls: true,
    servers: [
      { 
        host: "<host>",
        port: 27017,
      },
    ],
    credential: {
      username: "<user>",
      password: "<password>",
      db: "<db>",
      mechanism: "SCRAM-SHA-1",
    },
  });
    
 const db = client1.database("TestingDB");
    
 export default db;

This is not mentions in the document, but this will help to fix the issue

<db> is the database name, you can get the database name by following these steps

Step-1 step -1

Step-2 step-2

To find the <host> follow these steps

Step -1 enter image description here

Step -2 enter image description here

Step -3 enter image description here

like image 84
Prasath Avatar answered Jan 22 '26 23:01

Prasath