任何人都知道为什么我会收到此错误:“ 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 …Run Code Online (Sandbox Code Playgroud)