Deno Uncaught Error: No such host is known. (os error 11001)
Deno Uncaught Error: No such host is known. (os error 11001)
我尝试使用 https://deno.land/x/mongo@v0.21.2 框架将 MongoDB Atlas
连接到我的 Deno 应用程序。我尝试了以下代码 运行 我的应用程序。但是我得到一个错误 No such host is known. (os error 11001)
这里出了什么问题
Error
error: Uncaught Error: No such host is known. (os error 11001)
at unwrapResponse (rt_dispatch_json.js:24:13)
at sendAsync (rt_dispatch_json.js:75:12)
at async Object.connect (rt_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/mongo@v0.21.0/mod.ts";
const client1 = new MongoClient();
await client1.connect("mongodb+srv://user1:MYPASSWORD@cluster0.hmdnu.mongodb.net/TestingDB?retryWrites=true&w=majority");
const db = client1.database("TestingDB");
export default db;
我用这个命令 运行 我的服务器
deno run --allow-net --allow-write --allow-read --allow-plugin --unstable server.ts
我使用 https://www.youtube.com/watch?v=hhdhydffKKE 这个视频参考
解决了这个问题
按照以下步骤解决此问题
import { MongoClient } from "https://deno.land/x/mongo@v0.21.0/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
第一步
第二步
To find the <host>
follow these steps
步骤-1
步骤-2
步骤-3
我尝试使用 https://deno.land/x/mongo@v0.21.2 框架将 MongoDB Atlas
连接到我的 Deno 应用程序。我尝试了以下代码 运行 我的应用程序。但是我得到一个错误 No such host is known. (os error 11001)
这里出了什么问题
Error
error: Uncaught Error: No such host is known. (os error 11001)
at unwrapResponse (rt_dispatch_json.js:24:13)
at sendAsync (rt_dispatch_json.js:75:12)
at async Object.connect (rt_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/mongo@v0.21.0/mod.ts";
const client1 = new MongoClient();
await client1.connect("mongodb+srv://user1:MYPASSWORD@cluster0.hmdnu.mongodb.net/TestingDB?retryWrites=true&w=majority");
const db = client1.database("TestingDB");
export default db;
我用这个命令 运行 我的服务器
deno run --allow-net --allow-write --allow-read --allow-plugin --unstable server.ts
我使用 https://www.youtube.com/watch?v=hhdhydffKKE 这个视频参考
解决了这个问题按照以下步骤解决此问题
import { MongoClient } from "https://deno.land/x/mongo@v0.21.0/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
第一步
第二步
To find the
<host>
follow these steps
步骤-1
步骤-2
步骤-3