首页 > 解决方案 > MongoDb 连接字符串问题 - retryWrites Expected stringified boolean value

问题描述

我在连接到 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

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

有什么帮助吗?

标签: mongodbatlas

解决方案


我有同样的问题,并遇到了你的帖子。我发现我的连接中的问题是我有双引号和单引号"'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"

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


推荐阅读