提问人:Neno 提问时间:10/31/2023 最后编辑:PM 77-1Neno 更新时间:10/31/2023 访问量:55
您好,我正在尝试填写使用(HTML,CSS,JS,NODE.JS,PASSPORT.JS
Hello, i am trying to complete user registration form that uses (HTML,CSS,JS,NODE.JS,PASSPORT.JS
问:
我正在尝试使我的注册页面正常工作。当我输入用户名和密码时,我只得到.我收到以下错误:{"message":"Registration failed"}
MongooseError: Operation `users.findOne()` buffering timed out after 10000ms
at Timeout.<anonymous> (C:\path\to\your\file\node_modules\mongoose\lib\drivers\node-mongodb-native\collection.js:186:23)
at listOnTimeout (node:internal/timers:569:17)
at process.processTimers (node:internal/timers:512:7)
这是我用于用户注册表单的服务器.js代码:
app.post('/user/register', async (req, res) => {
const { username, password } = req.body;
try {
const existingUser = await User.findOne({ username });
if (existingUser) {
return res.status(409).json({ message: 'Username already exists' });
}
// Create a new user instance
const newUser = new User({ username, password });
// Save the user to the database
await newUser.save();
console.log('User registered successfully');
res.status(200).json({ message: 'User registered successfully' });
} catch (err) {
console.error(err); // Log the error for debugging
res.status(500).json({ message: 'Registration failed' });
}
});
您好,我正在尝试使我的注册页面正常工作。当我输入用户名和密码时,我只得到.我收到以下错误:现在我也收到,{"message":"Registration failed"}
MongooseError: Operation `users.findOne()` buffering timed out after 10000ms
at Timeout.<anonymous> (C:\Users\RistovskiWIN\Desktop\MladenWeb\node_modules\mongoose\lib\drivers\node-mongodb-native\collection.js:186:23)
at listOnTimeout (node:internal/timers:569:17)
at process.processTimers (node:internal/timers:512:7)
答: 暂无答案
评论