Mongodb Express网页未加载Mongoose抛出错误

Mongodb Express网页未加载Mongoose抛出错误,mongodb,express,mongoose,mongoose-web-server,Mongodb,Express,Mongoose,Mongoose Web Server,显然,我正在尝试建立一个注册系统,该系统失败,本地服务器网页未加载, 我的用户数据没有被发送到MongoDB,而且VS代码终端向我抛出错误 VS代码错误: (node:3188) UnhandledPromiseRejectionWarning: MongooseError: Operation `users.insertOne()` buffering timed out after 10000ms at Timeout.<anonymous> (E:\Projects\A

显然,我正在尝试建立一个注册系统,该系统失败,本地服务器网页未加载,
我的用户数据没有被发送到MongoDB,而且VS代码终端向我抛出错误

VS代码错误:

(node:3188) UnhandledPromiseRejectionWarning: MongooseError: Operation `users.insertOne()` buffering timed out after 10000ms
    at Timeout.<anonymous> (E:\Projects\Applications\chatter\node-rest-api\node_modules\mongoose\lib\drivers\node-mongodb-native\collection.js:185:20)
    at listOnTimeout (internal/timers.js:554:17)
    at processTimers (internal/timers.js:497:7)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:3188) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)
(node:3188) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
  • INDEX.JS

    const application = express();
    const mongoose = require("mongoose");
    const dotenv = require("dotenv");
    const helmet = require("helmet");
    const morgan = require("morgan");
    const userRoute = require("./routes/users");
    const authRoute = require("./routes/auth");
    
    dotenv.config();
    
    mongoose.connect(process.env.MONGO_URL, {useNewUrlParser: true, useUnifiedTopology: true}, () => {
        console.log("connected to MongoDB");
    });
    
    // middleware 
    application.use(express.json());
    application.use(helmet());
    application.use(morgan("common"));
    
    application.use("/api/users", userRoute);
    application.use("/api/auth", authRoute);
    
    application.listen(8800, () => {
        console.log("backend server has been setup and in running!");
    });
    
    
  • 我最初在/api/auth中更改代码后,我需要将URL更改为/api/auth/register,但加载要花很长时间

    开发人员工具(Ctrl+Shift+I)也显示了以下内容

    如我所述,您是否尝试过使用try-catch语句?如果您使用的是异步函数,请始终使用try-catch
    const application = express();
    const mongoose = require("mongoose");
    const dotenv = require("dotenv");
    const helmet = require("helmet");
    const morgan = require("morgan");
    const userRoute = require("./routes/users");
    const authRoute = require("./routes/auth");
    
    dotenv.config();
    
    mongoose.connect(process.env.MONGO_URL, {useNewUrlParser: true, useUnifiedTopology: true}, () => {
        console.log("connected to MongoDB");
    });
    
    // middleware 
    application.use(express.json());
    application.use(helmet());
    application.use(morgan("common"));
    
    application.use("/api/users", userRoute);
    application.use("/api/auth", authRoute);
    
    application.listen(8800, () => {
        console.log("backend server has been setup and in running!");
    });