SetOptionError: useFindAndModify: "useFindAndModify" is not a valid option to set

I have been trying to run my server but still facing this error.
I am in the initial stage of my full-stack application ( Mern stack) .

At first, I started working on backend and stuck while connecting with db.

I am attaching the picture and complete code with link for more reference.

import express from 'express';
import bodyParser from 'body-parser';
import mongoose from 'mongoose';
import cors from 'cors';

const app = express();

app.use(bodyParser.json({ limit: '30mb', extended: true }))
app.use(bodyParser.urlencoded({ limit: '30mb', extended: true }))


const PORT = process.env.PORT|| 5000;

mongoose.connect(CONNECTION_URL, { useNewUrlParser: true, useUnifiedTopology: true  })
  .then(() => app.listen(PORT, () => console.log(`Server Running on Port: http://localhost:${PORT}`)))
  .catch((error) => console.log(error.message));

mongoose.set('useFindAndModify', false);

@lasjorg Can you please help?

Remove the mongoose.set('useFindAndModify', false) option, it isn’t meant for the version of Mongoose you are using (it is for V5, not V7). You can’t use the deprecated methods anymore.

Or you can downgrade the version, but I don’t really see a good reason for it.