如何使用javascript

时间:2019-06-15 10:43:58

标签: javascript mongodb replicaset

无法连接到具有副本集的数据库

我有一个kubernetes集群,其中设置了我的数据库xyz,其中一个数据库有3个mongodb节点,以维持容错能力。

因此,为了连接到数据库xyz,我向mongodb副本集提供了以下条目。

mongodb://dbhost:port1,dbhost:port2,dbhost:port3/?replicaSet=rs0mongodb://dbhost:port1,dbhost:port2,dbhost:port3/xyz?replicaSet=rs0

我已经尝试过并搜索stackoverflow和google上的所有可用选项,但是它不起作用...  非常感谢您的帮助。

const url = await databaseConfig[env].dbhost;
const dbName = "xyz";
const client = await mongoClient.connect(url);
const db = await client.db(dbName);
  return Promise.all(
    studentNames.map(async function(studentName) {
      const uuid = await getStudentUUID(studentName);
      return db
        .collection("students")
        .deleteMany({ "id": "1234" });
        })
      );

我希望我的脚本可以连接到数据库,但是无法连接。

如果我指定启动的主节点,则我的脚本运行正常。问题只有当我们的主要需求下降并且我们需要通过副本集将其连接时

0 个答案:

没有答案
相关问题