gpt4 book ai didi

javascript - "Error: MongooseError: Operation ` users.insertOne() ` buffering timed out after 10000ms",

转载 作者:行者123 更新时间:2023-12-04 11:47:13 24 4
gpt4 key购买 nike

我在 node express 上运行 MongoDB Atlas,当我使用 postman 进行测试时出现此错误。

const express = require('express');
const cors = require('cors');
const mongoose = require('mongoose');

require('dotenv').config();

const app = express();
const port = process.env.PORT || 5000;

app.use(cors());
app.use(express.json());

const uri = process.env.ATLAS_URI;
mongoose.connect(uri, { useNewUrlParser: true, useCreateIndex: true }
);
const connection = mongoose.connection;
connection.once('open', () => {
console.log("MongoDB database connection established successfully");
})

const exercisesRouter = require('./routes/exercises');
const usersRouter = require('./routes/users');

app.use('/exercises', exercisesRouter);
app.use('/users', usersRouter);

app.listen(port, () => {
console.log(`Server is running on port: ${port}`);
});
这是我的 .env ,我猜问题可能也在这里,请帮助:
ATLAS_URI=mongodb+srv://userone:useronepassword1234@cluster0.swye5.mongodb.net/<dbname>?retryWrites=true&w=majority

最佳答案

就我而言,我必须去 Atlas,并将我的白名单 IP 重置为正确的地址。
然后我重新启动了我的本地服务器并尝试再次在 postman 上发帖......它成功了!

关于javascript - "Error: MongooseError: Operation ` users.insertOne() ` buffering timed out after 10000ms",,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65680842/

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