UnhandledPromiseRejectionWarning: MongoError: w 必须是连接处的数字或字符串

Pat*_*nda 3 mongodb express

任何人都知道为什么我会收到此错误:“ UnhandledPromiseRejectionWarning: MongoError: w 必须是 Connection 处的数字或字符串。” ? 我在运行下面的代码时遇到了这个错误。它的目的是检查用户是否在 mongodb 数据库中,如果不在,则通过用户电子邮件和哈希密码创建一个新用户。

我不知道是否有任何关系,代码似乎运行良好,但是当我昨天将我的 mac 更新为 catalina OS 时,我开始遇到这个问题。

routerAuth.post('/signup', (req, res, next) => {
    const result = Joi.validate(req.body, schema)
    if (result.error === null) {
        Profile.findOne({
            email: req.body.email
        }).then(profile => {
            if (profile) {
                const error = new Error(
                    'The email is already in use. Please choose another one'
                )
                res.status(409)
                next(error)
            } else {
                bcrypt.hash(req.body.password.trim(), 12).then(hashedpassword => {
                    let newProfile = new Profile({
                        first: req.body.first,
                        last: req.body.last,
                        password: hashedpassword,
                        email: req.body.email
                    })

                    Profile.insertMany(newProfile).then(profile => {
                        res.json(profile)
                    })
                })
            }
        })
    }
})
Run Code Online (Sandbox Code Playgroud)

And*_*szl 7

我不确定这个错误是从哪里来的(我发现了一个 2016 年的拉取请求,据称它解决了这个问题),但是当我更改 url 参数顺序时,我再也没有得到这个。

所以而不是这个:

/<database>?retryWrites=true&w=majority
Run Code Online (Sandbox Code Playgroud)

写这个:

/<database>?w=majority&retryWrites=true
Run Code Online (Sandbox Code Playgroud)