Node.js connection error

Hello, first time I am working with MongoDB and I struggling to connect it to my Node.js project.
Can someone please help with this error?


patre@LAPTOP-QGT1UHO7 MINGW64 /c/Programování/React/Projects/elektronickaEvidenceAstronautu (master)
$ node server
Server 5000!
            throw error;

Error: Connect error to MongoDB
    at C:\Programování\React\Projects\elektronickaEvidenceAstronautu\database\connect.js:12:23
    at C:\Programování\React\Projects\elektronickaEvidenceAstronautu\node_modules\mongoose\lib\helpers\promiseOrCallback.js:17:1
    at C:\Programování\React\Projects\elektronickaEvidenceAstronautu\node_modules\mongoose\lib\index.js:344:16
    at C:\Programování\React\Projects\elektronickaEvidenceAstronautu\node_modules\mongoose\lib\connection.js:825:14
    at processTicksAndRejections (node:internal/process/task_queues:96:5)


const Mongoose = require("mongoose");
const URL = "mongodb://******:******,,";

class dbConnect {
  connect() {
        useNewUrlParser: true,
        useUnifiedTopology: true,
        useFindAndModify: false,
        useCreateIndex: true
      },(err) => {
        if(err) throw new Error("Connect error to MongoDB");
        console.log("MongoDB connected!");

module.exports = dbConnect;

Thank you for advice.

It is failing at db connect stage
Can you connect to your db by shell using the same connect string?
We need exact error.From your code it appears to be generic error message

Today i had the exact same code and problem. I tried deleting some options and started working fine. I deleted:

  • useFindAndModify: false
  • useCreateIndex: true
1 Like

I figured out that recent versions of mongoose do not support anymore those options. If u still wanna use them, just change the mongoose version to 5.0.12

MongoParseError: options usecreateindex, usefindandmodify are not supported

1 Like

It works, thank you!

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.