2021年2月4日星期四

Unhandled Promise Rejection Warning: Mongoose Server Selection Error

UnhandledPromiseRejectionWarning: MongooseServerSelectionError Bug?*

What is the current behavior?

  • hello there I am trying to connect mongoose with URL string included everything is fine but after console.log("mongoDB database connection established successfully") this is not showing this console's text but an error is coming there Screenshot from 2021-02-03 14-54-33
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,useUnifiedTopology:true}       ); // update the code provided below  const connection = mongoose.connection; // why do you need this?  connection.once('open',() =>{  console.log("mongoDB database connection established successfully");  }) // no need to add connection again  app.listen(port, () => {    console.log(`server is running on port ${port}`);  });  

server.js file code above and in .env the URI key is given

What is the expected behavior?

  • the expected output is MongoDB database connection established successfully.

What are the versions of Node.js, Mongoose, and MongoDB you are using? Note that "latest" is not a version.

  • "cors": "^2.8.5", "dotenv": "^8.2.0", "express": "^4.17.1", "mongoose": "^5.11.14",
https://stackoverflow.com/questions/66049899/unhandled-promise-rejection-warning-mongoose-server-selection-error February 05, 2021 at 12:36AM

没有评论:

发表评论