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 }));
app.use(cors());
const CONNECTION_URL = 'mongodb+srv://humoudmajid:[email protected]/?retryWrites=true&w=majority'
const PORT = process.env.PORT || 5000;
mongoose.connect(CONNECTION_URL, { useNewUrlParser: true, useUnifiedTopology: true })
.then(() => app.listen(PORT, () => console.loq(`Server running on port: ${PORT}`)))
.catch((error) => console.log(error.message));
mongoose.set('useFindAndModify', false);
Im getting this error code.
/Users/humoudmajid/Desktop/Projects/libs/memories_project/server/node_modules/mongoose/lib/index.js:224
throw new Error(``${key}` is an invalid option.`);
^
Error: `useFindAndModify` is an invalid option.
at Mongoose.set (/Users/humoudmajid/Desktop/Projects/libs/memories_project/server/node_modules/mongoose/lib/index.js:224:11)
at file:///Users/humoudmajid/Desktop/Projects/libs/memories_project/server/index.js:20:10
at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:385:24)
at async loadESM (node:internal/process/esm_loader:88:5)
at async handleMainPromise (node:internal/modules/run_main:61:12)
[nodemon] app crashed - waiting for file changes before starting...
2
Answers
It’s deprecated now. You don’t need
mongoose.set('useFindAndModify', false);
. Just usemongoose.connect(CONNECTION_URL).then(()=>{console.log('...')})
Delete the line
useFindAndModify
is deprecated and not necessary anymore.