gpt4 book ai didi

Operation `users.insertOne()` buffering timed out after 10000ms in, Node.js, MongooseError(在10000ms in,Node.js,MongooseError之后,操作`users.intertOne()`缓冲超时)

转载 作者:bug小助手 更新时间:2023-10-27 20:42:02 30 4
gpt4 key购买 nike



I am busy creating a project which allows the user to enter "Email" & "Password" to register to the site,

我正忙着创建一个项目,允许用户输入“电子邮件”和“密码”注册到网站,


When I try to enter a user using the "Email" & "Password" to enter this site, I get the following error:

当我尝试使用“Email”和“Password”输入用户以进入此站点时,我收到以下错误:



MongooseError: Operation users.insertOne() buffering timed out after
10000ms


Unhandled rejection MongooseError: Operation users.findOne() buffering
timed out after 10000ms



I have tried all the proposed solutions I found here which have a similar problem, delete the node_modules folder and reinstall mongoose.

我已经尝试了我在这里找到的所有建议的解决方案,它们都有类似的问题,删除NODE_MODULES文件夹并重新安装Mongoose。


Please see my code below, thanks!

请看我下面的代码,谢谢!


const express = require("express");
const bodyParser = require("body-parser");
const ejs = require("ejs");
const mongoose = require("mongoose");

const app = express();

app.use(express.static("public"));
app.set('view engine', 'ejs');

app.use( bodyParser.urlencoded ({extended: true}));

mongoose.connect = ("mongodb://localhost:27017/userDB", {useNewUrlParser: true, useUnifiedTopology: true});

const userSchema = {
email: String,
password: String
};

const User = new mongoose.model("User", userSchema);

app.get("/", function(req, res){
res.render("home")
});

app.get("/login", function(req, res){
res.render("login")
});

app.get("/register", function(req, res){
res.render("register")
});

app.post("/register", function(req, res){
const newUser = new User({
email: req.body.username,
password: req.body.password
});
newUser.save(function(err){
if (err) {
console.log(err);
} else {
res.render("secrets");
}
});
});

Can anyone help me out?

有谁能帮帮我吗?


Atom images - Project SecretsCode

Atom图像-项目秘书代码


更多回答

Please provide the controller code

请提供控制器代码

Please see code above, I dont seem to see where my error is. thanks

请看上面的代码,我似乎看不出我的错误在哪里。谢谢

In your own words, what is the line mongoose.connect = (...) doing?

用你自己的话来说,什么是mongoose.Connect=(...)在做什么?

I hope i have this correct and clear enough, but mongoose.connect = (...), what is should do is connect to my localhost server? but when i start the server on port 3000 and navigate to the register screen, insert the details required, I get the error: MongooseError: Operation users.insertOne() buffering timed out after 10000ms Unhandled rejection MongooseError: Operation users.findOne() buffering timed out after 10000ms

我希望我有足够的正确和清楚,但mongoose.Connect=(...),它应该做的是连接到我的本地主机服务器?但是,当我在端口3000上启动服务器并导航到注册屏幕,插入所需的详细信息时,我收到错误:MongooseError:OPERATION USERRIS.INSERTONE()缓冲在10000ms后超时未经处理的拒绝MongooseError:OPERATION USERS.findOne()缓冲在10000ms后超时

Your internet connection is probably not strong enough to initiate and hold a database connection. That was my experience.

您的Internet连接可能不够强大,无法启动和保持数据库连接。那是我的经验。

优秀答案推荐

try adding one more line under mongoose.connect curly braces:-

尝试在mongoos下再添加一行。连接花括号:-


mongoose.connect("monogodb://localhost....,{useNewUrlParser:true,
useUnifiedTopology:true,
useCreateIndex:true}).then(()=>{
console.log(`successfully connected`);
}).catch((e)=>{
console.log(`not connected`);
})

you can check the error in console if not connected by replacing "not connected" with 'e'

如果未连接,您可以通过将“未连接”替换为“e”来检查控制台中的错误



I was having the same issue, Make sure that your mongoDB database username and password is alphanumeric with no special symbols. And dont add this:

我也遇到了同样的问题,请确保您的MongoDB数据库用户名和密码是由字母数字组成的,没有特殊符号。并且不要添加以下内容:


{useNewUrlParser:true,
useUnifiedTopology:true,
useCreateIndex:true})

simply write this:

简单地写一下:


mongoose.connect(process.env.MONGO_URL,).then(()=>{
console.log(`successfully connected`);
}).catch((e)=>{
console.log(`not connected`);
});


This worked for me.

这对我很管用。


const mongoose = require('mongoose');

mongoose.set('strictQuery', false);

mongoose.connect('mongodb://127.0.0.1:27017/student-reg').then(() => {
console.log(`successfully connected`);
}).catch((e) => {
console.log(`not connected`);
});



According to Mongoose documentation, if the connection fails on your machine, try replacing localhost with 127.0.0.1 in this line of code:

根据Mongoose文档,如果您的计算机上的连接失败,请尝试在以下代码行中将本地主机替换为127.0.0.1:


mongoose.connect('mongodb://localhost:27017/dbname', { useNewUrlParser: true, useUnifiedTopology: true });


For a reason my IP address changed, so I had to update it inside Mongo DB - NetworkAccess - Edit - Use the new IP address, maybe you'll see a button to update with current Ip or something like that, click it

由于某种原因,我的IP地址改变了,所以我不得不在Mongo DB-NetworkAccess-编辑-使用新的IP地址中更新它,也许你会看到一个按钮,用当前的IP或类似的东西更新,点击它



try this one :

试试这个:


    const userSchema = new mongoose.Schema({
email: String,
password: String
});

mongoose.model("User", userSchema);

const User = mongoose.model("User");

///////

app.post("/register", function(req, res){
const newUser = new User({
email: req.body.username,
password: req.body.password
});
newUser.save(function(err){
if (err) {
console.log(err);
} else {
res.render("secrets");
}
});
});

更多回答

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com