mongodb deno和mongo@v0.31.1的MongoConnection错误

laximzn5  于 2023-05-22  发布在  Go
关注(0)|答案(1)|浏览(136)

我无法从我的DENO应用程序连接到Mongo Atlas。它以某种方式工作-现在它不。我还检查了我的网络访问选项。
下面是我的代码:

import { dotEnvConfig, MongoClient } from "../deps.ts";
const configData = await dotEnvConfig();

const { MONGO_USER_NAME, MONGO_USER_PASSWORD, MONGO_HOSTNAME, MONGO_PORT } =
  configData;


const client = new MongoClient();

// Connecting to a Mongo Atlas Database
await client.connect({
  db: "dip",
  tls: true,
  servers: [
    {
      host: MONGO_HOSTNAME,
      port: 27017,
    },
  ],
  credential: {
    username: MONGO_USER_NAME,
    password: MONGO_USER_PASSWORD,
    db: "dip",
    mechanism: "SCRAM-SHA-1",
  },
});

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

export default db;

以下是我的错误:
error:Uncaught(in promise)错误:MongoError:“连接失败:找不到主节点”throw new MongoDriverError(Connection failed: ${e.message || e});
^ at MongoClient.connect(https://deno.land/x/mongo@v0.31.1/src/client.ts:46:13)at async file:///E:/webstuff/deno/db/mongodb. ts:12:1

nimxete2

nimxete21#

如果你的主集群没有改变,检查一下mongo atlas。这就是我的遭遇

相关问题