Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So I pretty much keep getting a nodemon error and Im not sure as to why it keeps saying my useAndModify is an invalid option and I'm not sure as to why as this is the right way to do this code I've recheked many times and still cant find a reason as I keep getting this error Ill post the error down below

(node:16864) ExperimentalWarning: The ESM module loader is experimental. C:\Users\drago\OneDrive\Documents\Third Year College\DataRep\Pro\server\node_modules\mongoose\lib\index.js:174 if (VALID_OPTIONS.indexOf(key) === -1) throw new Error(\${key}` is an invalid option.`); ^

Error: useFindAndModify is an invalid option. at Mongoose.set (C:\Users\drago\OneDrive\Documents\Third Year College\DataRep\Pro\server\node_modules\mongoose\lib\index.js:174:48) at file:///C:/Users/drago/OneDrive/Documents/Third%20Year%20College/DataRep/Pro/server/index.js:21:10 at ModuleJob.run (internal/modules/esm/module_job.js:110:37) at async Loader.import (internal/modules/esm/loader.js:179:24) [nodemon] app crashed - waiting for file changes before starting...

What I have tried:

<pre>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://Miles:Morales@cluster0.lic6t.mongodb.net/myFirstDatabase?retryWrites=true&w=majority';
const PORT = process.env.PORT || 5000;

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

mongoose.set('useFindAndModify', false);
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900