gpt4 book ai didi

mongodb - Deno 未捕获错误 : No such host is known.(操作系统错误 11001)

转载 作者:行者123 更新时间:2023-12-05 02:01:54 25 4
gpt4 key购买 nike

我尝试使用 https://deno.land/x/mongo@v0.21.2MongoDB Atlas 连接到我的 Deno 应用程序框架。我尝试了以下代码来运行我的应用程序。但我得到一个错误 No such host is known。 (操作系统错误 11001) 这里出了什么问题

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/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

第一步 step -1

第二步 step-2

To find the <host> follow these steps

步骤-1 enter image description here

步骤-2 enter image description here

步骤-3 enter image description here

关于mongodb - Deno 未捕获错误 : No such host is known.(操作系统错误 11001),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66202683/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com