我有一个 Koa 2 应用程序,并且 /signup 的帖子由此函数处理:
import User from 'models/user';
export const signup = async (ctx, next) => {
const { email, password } = ctx.request.body;
try {
const existingUser = await User.findOne({ email });
if (existingUser) {
ctx.body = { error: 'Email is in use' };
return next();
}
const user = new User({
email,
password,
});
await user.save();
ctx.body = { success: true };
} catch (e) {
next(e);
}
return next();
};
Run Code Online (Sandbox Code Playgroud)
该函数接收到正确的数据,但await User.findOne().exec();永远不会返回并卡住。
我认为问题出在那里,因为如果我删除,代码会正常执行。如果我切换到 …