【问题标题】:MongoDb connection string problem - retryWrites Expected stringified boolean valueMongoDb 连接字符串问题 - retryWrites Expected stringified boolean value
【发布时间】:2021-10-28 16:29:15
【问题描述】:

我在连接到 mongoDB 的 Atlas 集群时遇到问题。

如果我尝试获取一些数据,它会返回错误

“在副本集配置中找不到名为‘majority’的写入关注模式”

我查看了错误,每个人都说删除连接字符串末尾的&w=majority

这样做了,但现在我遇到了一个新错误

UnhandledPromiseRejectionWarning: MongoParseError: For retryWrites Expected stringified boolean value, got: true

我没有以任何方式修改字符串,它昨天还在工作。

我的字符串是

mongodb+srv://username:password@cluster0.yummd.mongodb.net/dbName?retryWrites=true&w=majority

字符串末尾没有空格或任何东西,不知道是什么。

有什么帮助吗?

【问题讨论】:

    标签: mongodb atlas


    【解决方案1】:

    我遇到了同样的问题,并遇到了您的帖子。 我发现我的连接中的问题是我有双引号而不是单引号"'mongodb+srv://username:password@database.aaaa.mongodb.net/collection?retryWrites=true&w=majority'"。所以简单的解决方案就是删除单引号。这为我解决了这个问题。然后你得到:"mongodb+srv://username:password@database.aaaa.mongodb.net/collection?retryWrites=true&w=majority"

    我不知道你是否已经解决了,但也许你还没有。

    【讨论】:

      【解决方案2】:

      您的 URI 中有一些不可打印的字符。手动输入,无需复制粘贴。

      【讨论】:

      • 感谢您的回答。但我并没有以任何方式对其进行真正的修改。过去几周,该字符串一直存在于 .env 文件中
      【解决方案3】:

      只需从 env 文件中删除 (;) 即可开始正常工作

      【讨论】:

      • 为什么你认为 env 文件中有一个;
      【解决方案4】:

      我遇到了同样的问题。

      可能有两个原因:

      1. dotenv.config(); 应该在const MongoStore = connectMongo; 上方

      2. 检查mongodburl 是否有空格和字符

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-09-20
        • 2011-04-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多