作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试使用 https://deno.land/x/mongo@v0.21.2 将 MongoDB 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
To find the
<host>
follow these steps
关于mongodb - Deno 未捕获错误 : No such host is known.(操作系统错误 11001),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66202683/
我是一名优秀的程序员,十分优秀!